The-Forge icon indicating copy to clipboard operation
The-Forge copied to clipboard

Add userdata to WidgetCallback

Open wutipong opened this issue 3 years ago • 2 comments

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.

  1. Bind a callback to a class member function (instead of static function)
captureBtn.pUserdata = this;
captureBtn.pOnEdited = [](void * user) { static_cast<MainApp*>(user)->Capture(); };
  1. 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;

wutipong avatar May 14 '21 21:05 wutipong

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.

wutipong avatar Sep 23 '21 07:09 wutipong

I am not sure if this is still meaningful with the current code base?

wolfgangfengel avatar Feb 12 '24 22:02 wolfgangfengel