Expand description
Input in, events out.
A runner feeds InputEvents, in logical coordinates, to
Core::handle_input. The core hit-tests
them against the frame that last finished (the standard immediate-mode
trade: a click lands on what was drawn) and answers with UiEvents:
plain data, each tagged with the node’s key, the origin that declared
the node (the host app or an extension) and the window, so the runner
can route it without knowing what either looks like.
What an input becomes depends on what the node under it declared: a
primary click on an on_click node is the node’s tag as the payload,
an on_hover node makes {kind:"hover", ...} events, a focused
editor takes InputEvent::Text and InputEvent::Key, a key sink
takes InputEvent::KeyDown and InputEvent::KeyUp.
use kui_core::{Core, InputEvent, NodeSpec, Size, Vec2};
let mut core = Core::new();
let mut ui = core.frame(Size::new(200.0, 100.0), 1.0);
ui.leaf_keyed("ok", NodeSpec::row().size(80.0, 30.0).on_click("ok"));
ui.finish();
// A click is a move, a press and a release; the release resolves it.
core.handle_input(InputEvent::CursorMoved(Vec2::new(10.0, 10.0)));
core.handle_input(InputEvent::mouse_down(1));
let events = core.handle_input(InputEvent::mouse_up());
assert_eq!(events.len(), 1);
assert_eq!(events[0].payload.as_str(), Some("ok"));
assert_eq!(Some(events[0].key), core.key_of("ok"));Structs§
- Buttons
- Which of the non-primary buttons a node’s
on_buttonclaims:Buttons::SECONDARY,Buttons::MIDDLEandButtons::OTHER(every button past the named three), or-ed together. A node declaringon_buttonclaimsButtons::ALLunless it says otherwise. The primary button is never in it: that one presses, drags and clicks for every node. - Clipboard
Marks - What the pasteboard said about the text a paste brought back: the markers
password managers set on a copied secret, after the
convention at nspasteboard.org that 1Password, Bitwarden, KeePassXC and
the macOS clipboard managers follow. Read by the driver, which owns the
clipboard, and handed over with the text as
InputEvent::Paste. - HitRegion
- HitShapes
- The points a frame’s stroke and fill shapes index, built beside its regions.
- Interaction
- KeyLocks
- What the lock keys hold at a press: Caps Lock and Num Lock on or off.
Not a modifier held —
KeyModsis only what is down, which accelerators and chords compare exactly — but state a press was made under, which a terminal speaking kitty’s keyboard protocol reports and a keypad reading needs (its1is an End with Num Lock off). - KeyMods
- Physical modifier state. Unlike
Mods— which abstracts platform conventions for the input widget (word,doc) — nothing here is normalized: an app bindingCtrl-wneeds to know it was Control and not Command. - KeyPress
- One key press, delivered to whatever holds key focus. Carries both the
binding view (
code+mods) and the typing view (text), so an app can serve a modal keymap and an insert mode from the same event. - Menu
Owner - The node whose
on_context_menua secondary press on a region opens: the region’s own node or an ancestor’s (seeHitRegion::context_menu). - Mods
- Modifier state for editing keys.
wordis Alt/Option (word-wise motion),docis the platform primary modifier (line/document-wise motion). - Scroll
Region - A scroll container’s on-screen area, for wheel routing — or an
on_scrollnode’s, which takes the wheel the same way and turns it into an event instead of an offset. - Scrollbar
Region - One scrollbar drawn this frame (logical coordinates), for thumb dragging
and track jumps. Rebuilt by
finish_framealongside the indicator quads. - UiEvent
- An event produced by the UI, ready for routing.
Enums§
- EditKey
- Editing keys, decoupled from any windowing library’s key codes.
- HitShape
- The shape inside a region’s rect that a point has to be in to hit it. The rect is always tested first, so a shape is evaluated only for the few regions under the pointer. Inline on the region rather than behind an index: the twenty bytes measured nothing on a 10k-region frame, so the simpler shape won. Points for a stroke or a fill live in the interaction’s own list, relative to the region’s top-left in logical px, copied at emission because the frame’s stores do not outlive the frame and a press does.
- Input
Event - KeyCode
- A physical key press: the full keyboard, decoupled from any windowing
library.
EditKeyis the input widget’s closed navigation vocabulary; this is what apps that own their own text model bind against — an editor with modal keymaps, a game, a scripted panel. - KeyLocation
- Where on the keyboard a key sits, for the keys that have twins: the
left or right Shift, Ctrl, Alt or Super, and the keypad’s digits,
operators, Enter and (with Num Lock off) arrows beside the main
block’s. Everything else is
Standard.codestays what the key is — the keypad’s1isChar('1'), its Enter isEnter— so a keymap that does not care reads nothing new, and one that does (a terminal speaking kitty’s keyboard protocol, a game) reads this. - KeyPhase
- Which half of a key’s life an event reports. Both halves arrive as one
{kind="key"}payload — the way a drag’s three phases and a hover’s two do — so an app binds one handler and matchesphase. - Layout
Script - Which alphabet the layout a press was typed on writes, as the platform answers it: what decides whose ASCII a keymap matches.
- Mouse
Button - Which button a press came from — driver-facing rather than shaped after any one windowing library, so every driver maps its own vocabulary onto this one.
- Option
AsAlt - Which Option keys act as Alt on macOS — what a frame
declares with
crate::Ui::option_as_alt. On a Mac, Option composes: ⌥m types “µ”, and ⌥u, ⌥e, ⌥i, ⌥n and ⌥` are dead keys that start an accent and wait for the next key, so the press never arrives as a key at all and a keymap that binds<A-u>never hears it. An Option key named here is Alt instead: it composes nothing, types nothing, and every key under it arrives as a chord of the key the layout prints unmodified — what a terminal’s “Option as Meta” and an editor’s Alt bindings want.None, the default, is the Mac’s own behaviour; one side leaves the other composing, so a user keepsüon the right Option while the left one is Alt. Other platforms have no such composition on Alt and read nothing here. - Scroll
Axis
Constants§
- MIN_
STROKE_ GRAB - The narrowest a stroke’s hit target gets, logical px, whatever its drawn width: a 1 px connector is a 4 px target, the way a 1 px splitter handle is wider than its line everywhere.
Functions§
- in_
polygon - Whether
pis inside the outline throughptsby the even-odd rule (the crossing test). A point on an edge counts as inside on one side and outside on the other, which is what every hit test of a shared edge between two wedges wants: exactly one of them. - in_
rounded_ rect - Whether
p(relative to the box’s top-left) is inside aw×hbox with the given corner radii: in the box, and not in a corner’s square past its arc. Radii are clamped to the half extents as the shader clamps them, so an oversized radius is the pill it draws as. - segment_
distance - Distance from
pto the segmenta–b.
Type Aliases§
- Button
Owner - The node a non-primary button’s press went to and whose capture it is
until the release: the nearest node at or above the
region pressed whose
on_buttonclaims that button. The same three fields asMenuOwner, resolved by the core at the press rather than carried on every region — a middle press is one event in a session, and a tag onHitRegionwould be a clone on every region of every frame. - Drop
Owner - The zone files dragged over a region land on: the region’s own node
or an ancestor’s (see
HitRegion::drop). The same three fields asMenuOwner, resolved by the same walk.