pub struct SliderState { /* private fields */ }Expand description
Controlled, allocation-free bounded value state for one slider.
The state is a plain copyable value. It owns the numeric contract—bounds, step snapping, thumb ordering, and the active thumb—while the application owns every visual declaration and decides when a change invalidates its window. It retains no allocation, task, timer, observer, or idle scheduler source.
Implementations§
Source§impl SliderState
impl SliderState
Sourcepub fn new(minimum: f64, maximum: f64, value: f64) -> Self
pub fn new(minimum: f64, maximum: f64, value: f64) -> Self
Create a single-thumb slider.
Non-finite bounds fall back to 0.0..=1.0, an inverted range is swapped, and an empty
range keeps one degenerate value at the minimum.
Sourcepub fn range(minimum: f64, maximum: f64, values: &[f64]) -> Self
pub fn range(minimum: f64, maximum: f64, values: &[f64]) -> Self
Create a multi-thumb range slider.
§Panics
Panics when values is empty or longer than MAX_SLIDER_THUMBS.
Sourcepub fn step(self, step: f64) -> Self
pub fn step(self, step: f64) -> Self
Replace the step used by arrow keys and pointer snapping.
A non-finite or non-positive step selects continuous movement, which snaps nothing.
Sourcepub fn large_step(self, large_step: f64) -> Self
pub fn large_step(self, large_step: f64) -> Self
Replace the amount moved by PageUp, PageDown, and shifted arrows.
The default is ten ordinary steps.
Sourcepub fn min_steps_between_values(self, steps: usize) -> Self
pub fn min_steps_between_values(self, steps: usize) -> Self
Keep adjacent thumbs at least this many steps apart, Base UI’s minStepsBetweenValues.
The gap is measured in whole steps, so a continuous slider — one with no step — ignores it. Existing values are re-ordered outward from the first thumb, and every later movement is clamped so the gap can never close.
Sourcepub const fn thumb_alignment(self, alignment: SliderThumbAlignment) -> Self
pub const fn thumb_alignment(self, alignment: SliderThumbAlignment) -> Self
Choose where a thumb sits relative to its value, Base UI’s thumbAlignment.
pub const fn orientation(self, orientation: SliderOrientation) -> Self
pub const fn vertical(self) -> Self
pub const fn disabled(self, disabled: bool) -> Self
pub const fn minimum(&self) -> f64
pub const fn maximum(&self) -> f64
pub const fn step_value(&self) -> f64
Sourcepub const fn large_step_value(&self) -> f64
pub const fn large_step_value(&self) -> f64
The amount one large step moves.
Without an explicit Self::large_step this is ten ordinary steps, or one tenth of the
range for a continuous slider.
pub const fn axis(&self) -> SliderOrientation
pub const fn is_disabled(&self) -> bool
Sourcepub const fn min_steps_between_values_value(&self) -> usize
pub const fn min_steps_between_values_value(&self) -> usize
The minimum whole-step gap kept between adjacent thumbs.
Sourcepub const fn thumb_alignment_value(&self) -> SliderThumbAlignment
pub const fn thumb_alignment_value(&self) -> SliderThumbAlignment
Where a thumb sits relative to its value.
Sourcepub const fn is_dragging(&self) -> bool
pub const fn is_dragging(&self) -> bool
Whether a captured pointer is currently dragging this slider, Base UI’s data-dragging.
Sourcepub fn end_drag(&mut self) -> bool
pub fn end_drag(&mut self) -> bool
End a drag started by Self::apply_pointer, returning whether the flag changed.
A captured pointer normally clears this itself; call it when the application cancels a drag for its own reasons.
Sourcepub fn thumb_offset(
&self,
index: usize,
track_length: f32,
thumb_length: f32,
) -> f32
pub fn thumb_offset( &self, index: usize, track_length: f32, thumb_length: f32, ) -> f32
The leading-edge offset of one thumb along the track, honoring the thumb alignment.
track_length and thumb_length are measured along the slider’s own axis, and the result
runs in that axis’s visual direction — left to right for a horizontal slider, top to bottom
for a vertical one, so a vertical minimum sits at the bottom.
pub const fn thumb_count(&self) -> usize
pub const fn active_thumb(&self) -> usize
Sourcepub const fn value(&self) -> f64
pub const fn value(&self) -> f64
The first thumb’s value, which is the whole value of a single-thumb slider.
pub fn values(&self) -> &[f64]
Sourcepub fn thumb_value(&self, index: usize) -> Option<f64>
pub fn thumb_value(&self, index: usize) -> Option<f64>
Read one thumb value, returning None past Self::thumb_count.
Sourcepub fn thumb_bounds(&self, index: usize) -> Option<(f64, f64)>
pub fn thumb_bounds(&self, index: usize) -> Option<(f64, f64)>
The inclusive bounds one thumb may move between, honoring its neighbors.
Sourcepub fn set_active_thumb(&mut self, index: usize) -> bool
pub fn set_active_thumb(&mut self, index: usize) -> bool
Make one thumb the target of keyboard actions, returning whether it changed.
Sourcepub fn set_thumb_value(&mut self, index: usize, value: f64) -> bool
pub fn set_thumb_value(&mut self, index: usize, value: f64) -> bool
Replace one thumb value, returning whether it changed.
The value is clamped into the slider bounds, snapped to the step, and then clamped between its neighboring thumbs so ordering can never invert.
Sourcepub fn set_value(&mut self, value: f64) -> bool
pub fn set_value(&mut self, value: f64) -> bool
Replace the first thumb value, returning whether it changed.
Sourcepub fn step_active(&mut self, steps: f64) -> bool
pub fn step_active(&mut self, steps: f64) -> bool
Move the active thumb by steps ordinary steps, returning whether it changed.
A continuous slider uses one percent of its range per step.
Sourcepub fn large_step_active(&mut self, forward: bool) -> bool
pub fn large_step_active(&mut self, forward: bool) -> bool
Move the active thumb by one large step, returning whether it changed.
Sourcepub fn active_to_minimum(&mut self) -> bool
pub fn active_to_minimum(&mut self) -> bool
Move the active thumb to its lowest reachable value, returning whether it changed.
Sourcepub fn active_to_maximum(&mut self) -> bool
pub fn active_to_maximum(&mut self) -> bool
Move the active thumb to its highest reachable value, returning whether it changed.
Sourcepub fn fraction(&self, index: usize) -> f32
pub fn fraction(&self, index: usize) -> f32
The 0.0..=1.0 position of one thumb along its track.
Applications use this to place a caller-owned thumb and size a caller-owned range fill. A vertical slider still returns zero at its minimum; invert it in the caller’s layout.
Sourcepub fn fraction_of(&self, value: f64) -> f32
pub fn fraction_of(&self, value: f64) -> f32
The 0.0..=1.0 position of an arbitrary value along the track.
Sourcepub fn value_for_fraction(&self, fraction: f32) -> f64
pub fn value_for_fraction(&self, fraction: f32) -> f64
The snapped value at one 0.0..=1.0 track position.
Sourcepub fn value_at(&self, offset: f32, length: f32) -> f64
pub fn value_at(&self, offset: f32, length: f32) -> f64
The snapped value under one pointer offset measured along a track of length pixels.
A vertical track measures from its top, where the maximum lives, matching desktop sliders.
Sourcepub fn nearest_thumb(&self, value: f64) -> usize
pub fn nearest_thumb(&self, value: f64) -> usize
The thumb whose value is closest to value, preferring the lower index on a tie.
Sourcepub fn apply_pointer(&mut self, event: &PointerEvent, track: Size) -> bool
pub fn apply_pointer(&mut self, event: &PointerEvent, track: Size) -> bool
Apply one captured pointer event over a track of the given size.
The application owns the track’s layout, so it passes the size it declared. A press picks the nearest thumb, makes it active, and jumps it to the pointer; subsequent moves drag that same thumb even outside the track. Returns whether any value or the active thumb changed.
Sourcepub fn apply_pointer_change(
&mut self,
event: &PointerEvent,
track: Size,
) -> SliderPointerChange
pub fn apply_pointer_change( &mut self, event: &PointerEvent, track: Size, ) -> SliderPointerChange
Apply one captured pointer event and report whether the drag also ended.
This is the same arithmetic as Self::apply_pointer with Base UI’s onValueCommitted
boundary exposed: committed is true exactly on the event that releases or cancels the
capture, which is when the application persists the value it has been previewing. The
dragging flag is maintained here too, so Self::is_dragging can restyle the thumb.
Trait Implementations§
Source§impl Clone for SliderState
impl Clone for SliderState
Source§fn clone(&self) -> SliderState
fn clone(&self) -> SliderState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SliderState
Source§impl Debug for SliderState
impl Debug for SliderState
Source§impl Default for SliderState
impl Default for SliderState
Source§impl PartialEq for SliderState
impl PartialEq for SliderState
impl StructuralPartialEq for SliderState
Auto Trait Implementations§
impl Freeze for SliderState
impl RefUnwindSafe for SliderState
impl Send for SliderState
impl Sync for SliderState
impl Unpin for SliderState
impl UnsafeUnpin for SliderState
impl UnwindSafe for SliderState
Blanket Implementations§
impl<T> Action for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.