ConfettiFX / The-Forge

The Forge Cross-Platform Rendering Framework PC Windows, Steamdeck (native), Ray Tracing, macOS / iOS, Android, XBOX, PS4, PS5, Switch, Quest 2
Apache License 2.0
4.71k stars 493 forks source link

Add userdata to WidgetCallback #196

Closed wutipong closed 5 months ago

wutipong commented 3 years ago

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 commented 2 years ago

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.

wolfgangfengel commented 6 months ago

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