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§
- Controls
Plugin - Plugin: registers the toggle + slider behavior systems and their outbound message types.
- Knob
Geometry - Knob and thumb geometry, resolved from CSS at spawn. Sits on the
<toggle>/<switch>track entity (consulted viaKnobGeometry::inset) and on the<slider>track entity (consulted viaKnobGeometry::thumb_size). An entity without this component usesKnobGeometry::default, which reproduces today’s hardcoded geometry exactly. - Slider
Changed - Emitted after a
SliderValueis updated by user drag / click. Carries the entity and the new clamped value. - Slider
Drag Origin - 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 bycancel_slider_drag_on_escape, and cleared on normalDragEndEventrelease. - Slider
Thumb - Marker for the thumb child entity spawned inside every
<slider>. Absolute-positioned;sync_slider_thumbplaces it along the track at(value - min) / (max - min). - Toggle
Changed - Emitted after a
Toggleableflips itscheckedstate in response to user input. Carries the entity and the new value. - Toggle
Knob - Marker for the knob child entity spawned inside every
<toggle>. Absolute-positioned;sync_toggle_visualsslides it left / right by the parent’s checked state. - Track
Style - The full track palette of a
<toggle>or<switch>, resolved at spawn from markup / CSS and refreshed by the restyle pass.sync_track_fillis the only thing that reads it, andTrackStyle::fill_foris 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 CSSknob-insetauthored). - THUMB_
SIZE - Fallback slider thumb diameter in logical pixels, used when the
entity carries no
KnobGeometry(e.g. no CSSthumb-sizeauthored). - 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
LineDeltanormalization (LINE_PXinlumen-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 bySliderValue::step_sizeper notch - wheel-up (a negative delta, away from the user) increases, matching Qt’sQSlider::wheelEvent. The wheel is consumed by the slider:lumen_primitives::scroll::accumulate_wheelstands 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
SliderDragOriginand the drag machinery is torn down -crate::drag::DragStateandPressedare removed, so the drag doesn’t resume while the button stays held and the eventual pointer release emits noClickEvent(no release commit). FiresSliderChangedwith 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::checkedevery time the entity - or a child of it, such as the spawnedToggleKnob- receives aClickEvent. FiresToggleChangedso the script host can echo it toon_toggle(id, checked). - move_
slider_ on_ keys - Keyboard control for a focused
<slider>. Reads the rawKeyPressedbus directly rather thanFocusedKey- the same patternlumen_primitives::tabs::dispatch_tab_keysuses for its roving-tabindex nav - since a slider isn’t aTextInputand doesn’t need the extradispatch_focused_keysrouting hop. - set_
slider_ on_ click - Click-anywhere-on-track: set
SliderValuebased on where in the track’s content rect the pointer landed. Clicks landing on theSliderThumbchild 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 theSliderThumbchild (the common grab) resolve to the parent slider (see [resolve_control]). - snapshot_
slider_ drag_ origin - On
DragStartEventtargeting a slider (or its thumb child), stash the current value so Escape can restore it. Ordered beforeset_slider_on_dragso the snapshot always precedes this tick’s moves. - sync_
slider_ thumb - Place the
SliderThumbchild along its track at(value - min) / (max - min), vertically centred. Runs every tick (the position depends on the track’s laid-out size, not justSliderValue); writes only when the target inset actually moved so change detection and relayout stay quiet on idle frames. - sync_
toggle_ visuals - Slide the
ToggleKnobchild of every<toggle>to the track end itsToggleable::checkedstate calls for, and size it from the laid-out track. The track fill itself belongs tosync_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’sVisuals::fill; the per-widget sync systems only move the knob.