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 NoneThe 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§
- Button
Event - A
{kind:"button"}event: a non-primary button anonButtonnode claimed, captured by it from press to release. - Drag
- A
{kind:"drag"}event: anonDragnode’s pointer capture. - Hover
- A
{kind:"hover"}event: anonHovernode entered or left. - Layout
- A
{kind:"layout"}event: anonLayoutnode’s placed rect. - Scroll
- A
{kind:"scroll"}event: the wheel over anonScrollnode. - Text
Input - A
{kind:"text"}event: what a focused key sink or editor was given to insert.
Enums§
- Button
Phase - Which part of a held non-primary button an event reports.
- Drag
Phase - Which part of a drag an event reports.
- HoverBy
- What moved to change the hover.
- Hover
Phase - Which half of a hover an event reports.