int TwAddButton(TwBar *bar, const char *name, TwButtonCallback callback, void *clientData, const char *def) |
---|
This function adds a button entry to a tweak bar. When the button is clicked by a user, the callback function provided to TwAddButton is called.
The tweak bar to which adding a new variable.
The name of the button. It will be displayed in the tweak bar if no label
is specified for this button. It will also be used to refer to this button in other functions, so choose a unique, simple and short name and avoid special characters like spaces or punctuation marks.
The callback function that will be called by AntTweakBar when the button is clicked.
You should define this callback function like this:
void TW_CALL Callback(void *clientData) { // do something }
For your convenience, this is a supplementary pointer that will be passed to the callback function when it is called. For instance, if you set it to an object pointer, you can use it to access to the object’s members inside the callback function.
An optional definition string used to modify the behavior of this new entry. This string must follow the variable parameters syntax, or set to NULL
to get the default behavior. It could be set or modified later by calling the TwDefine or TwSetParam functions.
void TW_CALL RunCB(void * /*clientData*/) { Gump.State = RUNNING; } // ... TwAddButton(bar, "Run", RunCB, NULL, " label='Run Forest' ");
If you add a button without specifying callback
and clientData
(ie. they are set to NULL
), no button icon is displayed. Only the name or label of the button is displayed, and it is not clickable. It looks like a comment. This is a way to add a line of text in a tweak bar.
Example:
TwAddButton(bar, "comment1", NULL, NULL, " label='Life is like a box a chocolates' ");