I'm trying to write a GUI library for a project (also for learning purposes) from scratch (in C++), and it's working pretty well, but since this is my first attempt i feel that the design of the event system isn't that great.
basically, how i'm handling events now is that whenever a mouse click occurs i iterate over all the Widgets (buttons, for example) and test whether the mouse coordinates reside in one of them, and if so i call the event callback (a function pointer) which is stored in the button class itself!
so i was thinking of a different (better?) design:
What i want to have instead is an Event-Queue where whenever an event happens (a button clicked for example) i do the same thing as before (i.e. find out which button was clicked) and then construct an object of that event (i.e. ButtonClickedEvent) and add it to the queue and handle it later on, after rendering the frame, for example.
and this is where i'm getting confused about it.
how should i structure the whole thing without creating a mess? in other words, is there a standard-ish way of doing it?
i've been looking around for some info about this but all i find is how events can be handled in existing libraries (like java swing, QT, ...etc).
so if anyone here could explain how it works, that would be much appreciated!