Skip to main content

Module controls

Module controls 

Source
Expand description

Stateful control behaviors for the <toggle> and <slider> markup tags.

Each control owns a single component holding its current value (Toggleable.checked, SliderValue.value). These systems map raw ClickEvent / DragStartEvent / DragMoveEvent messages into state mutations on the matching entity. Script-facing notifications (ToggleChanged / SliderChanged) fire on every state change so the Rhai host can forward them as on_toggle(id, checked) / on_slider(id, value).

Structs§

ControlsPlugin
Plugin: registers the toggle + slider behavior systems and their outbound message types.
KnobGeometry
Knob and thumb geometry, resolved from CSS at spawn. Sits on the <toggle> / <switch> track entity (consulted via KnobGeometry::inset) and on the <slider> track entity (consulted via KnobGeometry::thumb_size). An entity without this component uses KnobGeometry::default, which reproduces today’s hardcoded geometry exactly.
SliderChanged
Emitted after a SliderValue is updated by user drag / click. Carries the entity and the new clamped value.
SliderDragOrigin
Pre-drag value snapshot for the Escape-cancel path. Inserted on the slider entity at DragStartEvent (whether the grab landed on the slider or its thumb child), consumed by cancel_slider_drag_on_escape, and cleared on normal DragEndEvent release.
SliderThumb
Marker for the thumb child entity spawned inside every <slider>. Absolute-positioned; sync_slider_thumb places it along the track at (value - min) / (max - min).
ToggleChanged
Emitted after a Toggleable flips its checked state in response to user input. Carries the entity and the new value.
ToggleKnob
Marker for the knob child entity spawned inside every <toggle>. Absolute-positioned; sync_toggle_visuals slides it left / right by the parent’s checked state.
TrackStyle
The full track palette of a <toggle> or <switch>, resolved at spawn from markup / CSS and refreshed by the restyle pass. sync_track_fill is the only thing that reads it, and TrackStyle::fill_for is the only place a state maps to a color.

Constants§

KNOB_FILL
Fill for the toggle knob / slider thumb child tiles.
KNOB_INSET
Fallback gap between the toggle knob and the track edge, in logical pixels, used when the entity carries no KnobGeometry (e.g. no CSS knob-inset authored).
THUMB_SIZE
Fallback slider thumb diameter in logical pixels, used when the entity carries no KnobGeometry (e.g. no CSS thumb-size authored).
TOGGLE_CHECKED_BG
Track fill for a checked <toggle> when no :checked { bg: ... } rule supplied one. Accent teal so checked vs unchecked is visible with zero author CSS.
TOGGLE_UNCHECKED_BG
Track fill for an unchecked <toggle> when neither markup nor CSS supplied one. Matches the default skin’s #555555.
WHEEL_NOTCH_PX
One wheel line-notch in logical pixels. Must match the window backend’s LineDelta normalization (LINE_PX in lumen-window-winit), so one physical wheel detent maps to exactly one slider step; pixel-precise trackpad deltas scale proportionally.

Functions§

adjust_slider_on_wheel
Wheel over a hovered <slider> (or its thumb child) nudges the value by SliderValue::step_size per notch - wheel-up (a negative delta, away from the user) increases, matching Qt’s QSlider::wheelEvent. The wheel is consumed by the slider: lumen_primitives::scroll::accumulate_wheel stands down whenever a slider sits on the hovered entity’s ancestor chain, so adjusting a slider never also scrolls an ancestor scroll container.
cancel_slider_drag_on_escape
Escape while a slider drag is in flight cancels it (Qt drag-cancel contract): the value snaps back to its SliderDragOrigin and the drag machinery is torn down - crate::drag::DragState and Pressed are removed, so the drag doesn’t resume while the button stays held and the eventual pointer release emits no ClickEvent (no release commit). Fires SliderChanged with the restored value so bound signals / scripts roll back too.
clear_slider_drag_origin_on_end
A drag that ends normally (pointer release) commits the dragged value: drop the snapshot so a later Escape doesn’t roll back a finished interaction.
flip_toggle_on_click
Flip Toggleable::checked every time the entity - or a child of it, such as the spawned ToggleKnob - receives a ClickEvent. Fires ToggleChanged so the script host can echo it to on_toggle(id, checked).
move_slider_on_keys
Keyboard control for a focused <slider>. Reads the raw KeyPressed bus directly rather than FocusedKey - the same pattern lumen_primitives::tabs::dispatch_tab_keys uses for its roving-tabindex nav - since a slider isn’t a TextInput and doesn’t need the extra dispatch_focused_keys routing hop.
set_slider_on_click
Click-anywhere-on-track: set SliderValue based on where in the track’s content rect the pointer landed. Clicks landing on the SliderThumb child resolve to the parent slider (see [resolve_control]). Coarse positioning; the drag handler refines from there.
set_slider_on_drag
While the user drags a slider, continuously update its value based on the cursor x within the track. Reuses DragMoveEvent, so the slider inherits all of lumen-input’s per-OS drag-threshold behavior for free. Drags that started on the SliderThumb child (the common grab) resolve to the parent slider (see [resolve_control]).
snapshot_slider_drag_origin
On DragStartEvent targeting a slider (or its thumb child), stash the current value so Escape can restore it. Ordered before set_slider_on_drag so the snapshot always precedes this tick’s moves.
sync_slider_thumb
Place the SliderThumb child along its track at (value - min) / (max - min), vertically centred. Runs every tick (the position depends on the track’s laid-out size, not just SliderValue); writes only when the target inset actually moved so change detection and relayout stay quiet on idle frames.
sync_toggle_visuals
Slide the ToggleKnob child of every <toggle> to the track end its Toggleable::checked state calls for, and size it from the laid-out track. The track fill itself belongs to sync_track_fill.
sync_track_fill
Paint every <toggle> / <switch> track with the fill its current state calls for. This is the single owner of a track’s Visuals::fill; the per-widget sync systems only move the knob.