GGUI/Public/UIEvents.h file

UI events: input, and how elements react to it.

Input reaches a document in two steps, on two threads:

  1. The thread that owns the pointer (for the engine: Sentinel) asks a PointerRouter whether the UI takes an input, using only the last published snapshot. Taken input is queued for the document; the rest goes to the game. No handlers run here.
  2. The UI update passes each queued input to UIContext::Dispatch, which updates hover and pressed state and runs handlers, before re-running, layout, and paint. A click's effect is in the next frame drawn.

Elements declare reactions while being built:

if (auto row = ui.Row({ .Class = "scenario" }))
{
    ui.OnClick([scenario] { Select(scenario); });
    ui.OnHover([scenario](bool bInside) { Preview(scenario, bInside); });
    ui.Label(NameOf(scenario));
}

A pointer event goes to the element under the pointer, then bubbles up to the first ancestor with a handler for it. Call event.Pass() to let it keep bubbling.

Namespaces

namespace GGUI

Classes

struct GGUI::InputEvent
One input, in document space (UI units, origin top left).
struct GGUI::TextInputEvent
Text delivered to the focused widget.
struct GGUI::KeyEvent
A key, as a key handler hears it.
struct GGUI::PointerEvent
A pointer event, as a handler hears it.
class GGUI::GGHandler
GGHandler: an event handler stored on a node.
template<typename TEvent>
class GGUI::HandlerOf
A handler of events of type TEvent: a lambda taking the event, or nothing.
struct GGUI::DispatchStats
What one UIContext::Dispatch did.
class GGUI::PointerRouter
PointerRouter: does the UI take this input, or does the game?
struct GGUI::PointerRouter::Decision
What to do with an input.
class GGUI::KeyRouter
KeyRouter: is this key the UI's or the game's?