Skip to main content

Module event

Module event 

Source
Expand description

Typed readings of the core’s own event payloads: drags, buttons, scrolls, hovers, layouts, key presses and text input.

A payload is a Value because it crosses into Lua, Node and C in one shape. Rather than reading it back field by field (get_f32("x"), get_str("phase")), a Rust handler asks for the view it wants; each view is None for an event of another kind.

use kui_core::{Key, OriginId, UiEvent, Value};
use kui_core::event::DragPhase;

// What an `on_drag` node emits as the pointer moves.
let ev = UiEvent::on(OriginId::HOST, Key::ROOT, Value::map([
    ("kind", Value::str("drag")),
    ("phase", Value::str("move")),
    ("x", Value::float(40.0)), ("y", Value::float(12.0)),
    ("dx", Value::float(8.0)), ("dy", Value::float(0.0)),
    ("tag", Value::str("splitter")),
]));

let d = ev.drag().expect("a drag");
assert_eq!(d.phase, DragPhase::Move);
assert_eq!(d.delta.x, 8.0);
assert_eq!(ev.tag().and_then(Value::as_str), Some("splitter"));
assert!(ev.scroll().is_none()); // another kind reads as None

The app’s own tag is still UiEvent::message or UiEvent::tag; these are the fields the core adds around it. Nothing here changes what an event carries.

Structs§

ButtonEvent
A {kind:"button"} event: a non-primary button an onButton node claimed, captured by it from press to release.
Drag
A {kind:"drag"} event: an onDrag node’s pointer capture.
Hover
A {kind:"hover"} event: an onHover node entered or left.
Layout
A {kind:"layout"} event: an onLayout node’s placed rect.
Scroll
A {kind:"scroll"} event: the wheel over an onScroll node.
TextInput
A {kind:"text"} event: what a focused key sink or editor was given to insert.

Enums§

ButtonPhase
Which part of a held non-primary button an event reports.
DragPhase
Which part of a drag an event reports.
HoverBy
What moved to change the hover.
HoverPhase
Which half of a hover an event reports.