Skip to main content

SliderState

Struct SliderState 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn thumb_alignment(self, alignment: SliderThumbAlignment) -> Self

Choose where a thumb sits relative to its value, Base UI’s thumbAlignment.

Source

pub const fn orientation(self, orientation: SliderOrientation) -> Self

Source

pub const fn vertical(self) -> Self

Source

pub const fn disabled(self, disabled: bool) -> Self

Source

pub const fn minimum(&self) -> f64

Source

pub const fn maximum(&self) -> f64

Source

pub const fn step_value(&self) -> f64

Source

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.

Source

pub const fn axis(&self) -> SliderOrientation

Source

pub const fn is_disabled(&self) -> bool

Source

pub const fn min_steps_between_values_value(&self) -> usize

The minimum whole-step gap kept between adjacent thumbs.

Source

pub const fn thumb_alignment_value(&self) -> SliderThumbAlignment

Where a thumb sits relative to its value.

Source

pub const fn is_dragging(&self) -> bool

Whether a captured pointer is currently dragging this slider, Base UI’s data-dragging.

Source

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.

Source

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.

Source

pub const fn thumb_count(&self) -> usize

Source

pub const fn active_thumb(&self) -> usize

Source

pub const fn value(&self) -> f64

The first thumb’s value, which is the whole value of a single-thumb slider.

Source

pub fn values(&self) -> &[f64]

Source

pub fn thumb_value(&self, index: usize) -> Option<f64>

Read one thumb value, returning None past Self::thumb_count.

Source

pub fn thumb_bounds(&self, index: usize) -> Option<(f64, f64)>

The inclusive bounds one thumb may move between, honoring its neighbors.

Source

pub fn set_active_thumb(&mut self, index: usize) -> bool

Make one thumb the target of keyboard actions, returning whether it changed.

Source

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.

Source

pub fn set_value(&mut self, value: f64) -> bool

Replace the first thumb value, returning whether it changed.

Source

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.

Source

pub fn large_step_active(&mut self, forward: bool) -> bool

Move the active thumb by one large step, returning whether it changed.

Source

pub fn active_to_minimum(&mut self) -> bool

Move the active thumb to its lowest reachable value, returning whether it changed.

Source

pub fn active_to_maximum(&mut self) -> bool

Move the active thumb to its highest reachable value, returning whether it changed.

Source

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.

Source

pub fn fraction_of(&self, value: f64) -> f32

The 0.0..=1.0 position of an arbitrary value along the track.

Source

pub fn value_for_fraction(&self, fraction: f32) -> f64

The snapped value at one 0.0..=1.0 track position.

Source

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.

Source

pub fn nearest_thumb(&self, value: f64) -> usize

The thumb whose value is closest to value, preferring the lower index on a tie.

Source

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.

Source

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

Source§

fn clone(&self) -> SliderState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SliderState

Source§

impl Debug for SliderState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SliderState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for SliderState

Source§

fn eq(&self, other: &SliderState) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SliderState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Action for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more