TwType TwDefineStruct(const char *name, const TwStructMember *structMembers, unsigned int nbMembers, size_t structSize, TwSummaryCallback summaryCallback, void *summaryClientData) |
---|
This function creates a new TwType corresponding to a C/C++ structure. Thus it could be used with TwAddVar* functions to control variable of type struct.
Specify a name for the struct type (must be unique).
An array of elements of type TwStructMember containing the descriptions of the structure members.
Number of elements of the structMembers array.
Size of the C/C++ structure (in bytes).
An optional callback function that will be called to display a summary of the structure content. If summaryCallback
is NULL
, a default summary will be displayed.
The callback function should be declared like this:
void TW_CALL SummaryCallback(char *summaryString, size_t summaryMaxLength, const void *value, void *summaryClientData); { const MyStruct *s = *(const MyStruct *)value; s->PrintToString(summaryString, summaryMaxLength); // for instance. // summaryString is a pre-allocated C string (zero-ended) to be filled. // Its maximum length is summaryMaxLength. }
For your convenience, this is a supplementary pointer that will be passed to the summaryCallback
function when it is called.
// A user defined structure typedef struct { int X; float F; void *P; int Y; } MyStruct; MyStruct elem; // an element of type MyStruct that we want to add to a tweak bar // Description of the structure (note that you are not required to describe all members, and that members can be reordered) TwStructMember myStructMembers[] = { { "x", TW_TYPE_INT32, offsetof(MyStruct, X), "min=0 max=9" }, { "y", TW_TYPE_INT32, offsetof(MyStruct, Y), "" }, { "f", TW_TYPE_FLOAT, offsetof(MyStruct, F), "step=0.1" } }; TwType myStructType; // ... // Define myStructType myStructType = TwDefineStruct("MyStructType", myStructMembers, 3, sizeof(MyStruct), NULL, NULL); // Add elem to bar TwAddVarRW(bar, "Elem", myStructType, &elem, NULL);