Simple GUI Library
gui_event_dispatching.h File Reference
#include <vector>
#include "sml/events/event_dispatching.h"
#include "sml/events/listener_notifier.h"
#include "sml/events/system_events.h"
#include "gui_event.h"
Include dependency graph for gui_event_dispatching.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  GuiEventDispatcher
 
class  GuiEventDispatchChain
 

Functions

Sml::Event * fireEvent (Sml::Event *event)
 Fire the event from the specified. More...
 

Detailed Description

The event proccessing is split into several stages.

  1. Creating GuiEvent. In most cases, this is done internally by the system. The system registers a system event (e.g. MouseMoved, KeyPressed, etc.).
  2. Determining the EventTarget. Then the system determines to which component the event should be sent. Some examples include:
    • A keyboard event is sent to the currently focused component.
    • A mouse event is sent to the component on which the cursor is pointed.
  3. Building a GuiEventDispatchChain from event target. The system then calls fireEvent(GuiEvent*) function with the event target determined by the previous stage. fireEvent(GuiEvent*) builds a dispatch chain and sends the event through it.
  4. Capturing phase. /---—\ /---------—\ /---------------—\ | Root | --> | Component1 | --> ... --> | Target component | ---—/ ---------—/ ---------------—/ Dispatcher Dispatcher Dispatcher Filter1 Filter1 Filter1 ... ... ...
    FilterN FilterN FilterN

    The next stage is moving the event from the root to the target. Each component has its own GuiEventDispatcher which calls filters on the event. A filter can consume the event and then the dispatching proccess terminates (though all of the current dispatcher's filters are called nonetheless).

  5. Bubbling phase. /---—\ /---------—\ /---------------—\ | Root | --> | Component1 | --> ... --> | Target component | ---—/ ---------—/ ---------------—/ Dispatcher Dispatcher Dispatcher Handler1 Handler1 Handler1 ... ... ... HandlerN HandlerN HandlerN

    The next stage is moving the event from the target to the root. Here each dispatcher calls handlers on the event. A handler can consume the event and then the dispatching proccess terminates (though all of the current dispatcher's handlers are called nonetheless). Most target components consume the event and the bubbling phase doesn't occur.

Author
Nikita Mochalov (github.com/tralf-strues)
Date
2021-11-06

Definition in file gui_event_dispatching.h.

Function Documentation

◆ fireEvent()

Sml::Event * fireEvent ( Sml::Event *  event)

Fire the event from the specified.

event->target

.

Build a GuiEventDispatchChain from target to the root component and send the event through it.

Parameters
event
Returns
The return event or nullptr if the event has been consumed.

Definition at line 13 of file gui_event_dispatching.cpp.