I have started planning the new callback system for v0.6 and I could use some opinions.
Note that v0.6 probably won't be released this year, so you won't see this new callback system soon.
Right now, callbacks are send after changing the callbackID of the object. All callbacks are polled later in the main loop (so no immediate callbacks). This also means that all callbacks come together in one place, where you have to distinct them from each other with the callbackID.
In v0.6 you will be able to intercept callbacks on 3 different levels:
- You can tell a single object to send callback to a specific function (so the callbacks can be spread over multiple functions).
- You can set a global callback function which receives the callback from all objects (unlike with polling, you get callbacks immediately).
- Or you can keep using the current way, by polling them from the window.
Objects will also send callbacks for more reasons. Until now callbacks were limited and were either on or off.
In v0.6 you will be able to choose exactly which callback you want.
If you e.g. want to make a button react on mouse down instead of on mouse click then you can simply do this:
button->callbacks = tgui::Button::LeftMouseDown;
(Right now, a button will send both mouse down and mouse click events, so you must filter it when you receive the callback)
Callbacks can be combined, so if you want to know when your edit box get focused or unfocused then just set both triggers:
editBox->callbacks = tgui::EditBox::Focus | tgui::EditBox::Unfocus;
The following four triggers will be added to all objects: Focus, Unfocus, MouseEnter, MouseLeave. And even more may be added in the future. They couldn't be added before because you would be overwhelmed by callbacks, but when you can choose the needed callbacks, I can easily add them.
Let me know what you think about this new way of handling callbacks.
Any ideas, comments or critics are welcome.