libglui / glui

GLUI is a GLUT-based C++ user interface library which provides controls such as buttons, checkboxes, radio buttons, and spinners to OpenGL applications. It is window-system independent, using GLUT or FreeGLUT.
Other
200 stars 81 forks source link

GLUI_Control ptr in callbacks #44

Open josch opened 9 years ago

josch commented 9 years ago

https://sourceforge.net/p/glui/feature-requests/8/

For callbacks, GLUI should pass a pointer to the control that triggered the callback. Currently the callbacks just give you an int, but that means if you want to take action that depends on the data in a control, then you need to have BOTH a callback function AND a variable somewhere in your code that's accessible to the function. If GLUI would pass a pointer to the GLUI_Control in the callback, I wouldn't have to hold onto that GLUI_EditText myself.

My code is littered with static variables that are there for the sole purpose of letting me know what the current string value is in a text field when I get the callback. There's no reason for GLUI not to pass just that pointer to me.

And while we're at it, it would be better if the int id value passed was a void instead so that you could have the callback pass you any old user data you want. Yes i know I could cast pointers to ints, but I don't think C++ guarantees that sizeof(int)==sizeof(void).

So in summary, I think the glui callback protoptype should be typedef void (GLUI_Update_CB) (void data, GLUI_Controlcontrol); instead of typedef void (GLUI_Update_CB) (int id);