Closed brianwatling closed 4 months ago
Just mostly concerned that we now have two different methods of invoking events now. But overall this is a good approach that does give more control over how data is passed across the widgets.
I did this to preserve backwards compatibility and avoid an unused user_data parameter on all existing callback functions. But I think this concern is valid enough to warrant breaking backwards compatibility, so I've updated things to always have a user_data parameter on callbacks. I did keep two versions of the functions to set event handlers - one without user_data and destructor - to keep things simple/clean for the basic case (but LMK if you think we should just have one way to set events always with user_data and dtor)
Fixes #69
A new struct
nk_console_event_handler
is introduced to expand what callbacks can do by adding per-callback data and a destructor. The per-callback data is passed to every call and the destructor is called when overwriting the callback or when the associated widget is destroyed (exactly like c++ object lifetime).nk_console_event
is left intact and a shim layer is added to allow nearly perfect backwards compatibility (ex. users should call nk_console_set_onchange() instead of settingonchange
directly)This enables users to perform more complex logic and/or use the same callback for multiple widgets.
C++ wrappers are provided to allow users to easily set a C++ lambda as a callback: