The-Forge
The-Forge copied to clipboard
Add userdata to WidgetCallback
Currently WidgetCallback
has no way to send custom userdata
into the callback. If there's a way to gives a userdata
it would be more flexible to use the GUI system.
Here's some scenario where the userdata
can be beneficial. Given that the IWidget
has one more field called pUserdata
which will be used during calling the associated callbacks.
- Bind a callback to a class member function (instead of static function)
captureBtn.pUserdata = this;
captureBtn.pOnEdited = [](void * user) { static_cast<MainApp*>(user)->Capture(); };
- Bind multiple widgets to the same function (instead of creating multiple function that calls the same function).
void onButtonPressed(void *userdata) {
ButtonWidget *button = (ButtonWidget *)userdata;
button->mDeactivated = true;
}
button1.pUserdata = &button1;
button1.pOnEdited = onButtonPressed;
button2.pUserdata = &button2;
button2.pOnEdited = onButtonPressed;
I think, the InputActionCallback
gets much more details comparing to the WidgetCallback
, which is a good thing. Now only if WidgetCallback
get the same level of attention.
I am not sure if this is still meaningful with the current code base?