Search code examples
language-agnosticframework-design

How would I propagate mouse and keyboard events in a UI framework?


I have finished the work on the render buffer and basic message pump of my console user interface framework, but now I have to propagate events to all the widgets (controls) on the screen.

Apparently I have two options:

  • Central registration of all controls with the message pump (which I think is not so good)

or

  • Hierarchical propagation through the "visual tree"

How would you go about it?


Solution

  • It's hard to give a definitive answer without knowing more about your framework, but I think registering all your widgets and message pump with some kind of mediator class would be the best option. If you try propagating your events through a hierarchy it could get very messy and your event-handling logic is going to be spread all over the place, making for unmaintainable code.