Skip to main content

set_slider_on_click

Function set_slider_on_click 

Source
pub fn set_slider_on_click(
    clicks: MessageReader<'_, '_, ClickEvent>,
    q: Query<'_, '_, (&mut SliderValue, &Transform, Option<&KnobGeometry>)>,
    parents: Query<'_, '_, &ChildOf>,
    out: MessageWriter<'_, SliderChanged>,
)
Expand description

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.

The pointer fraction is continuous and the slider’s positions are not, so the landing value goes through SliderValue::snap - a click on a step="1024" slider writes a multiple of 1024, the same as an arrow key.