Skip to main content

RangeSlider

Struct RangeSlider 

Source
pub struct RangeSlider<'a, T: Numeric> { /* private fields */ }
Expand description

A horizontal numeric range slider with two thumbs.

Both endpoints are bound to caller-owned values; the widget keeps low <= high automatically (a thumb dragged past its sibling clamps to the sibling’s value rather than swapping).

let (mut lo, mut hi): (u32, u32) = (24, 118);
ui.add(
    RangeSlider::new(&mut lo, &mut hi, 0u32..=200u32)
        .label("Price")
        .suffix("$"),
);

Implementations§

Source§

impl<'a, T: Numeric> RangeSlider<'a, T>

Source

pub fn new(low: &'a mut T, high: &'a mut T, range: RangeInclusive<T>) -> Self

Create a range slider bound to low and high, constrained to range.

Source

pub fn label(self, label: impl Into<WidgetText>) -> Self

Show a label on the left of the header row above the track.

Source

pub fn suffix(self, suffix: impl Into<String>) -> Self

Suffix appended to each formatted endpoint value (e.g. "%", " dB").

Source

pub fn decimals(self, n: usize) -> Self

Number of decimal places in the value display. Defaults to 0 for integer-typed sliders and 2 for float-typed.

Source

pub fn value_fmt(self, fmt: impl Fn(f64) -> String + 'a) -> Self

Custom formatter applied to both endpoint values. Overrides suffix and decimals.

Source

pub fn show_value(self, show: bool) -> Self

Hide the right-aligned low – high display in the header row. The label, if any, still renders. Default: shown.

Source

pub fn step(self, step: f64) -> Self

Snap values to multiples of step (in the slider’s value units). Integer-typed sliders snap to 1.0 automatically unless overridden.

Source

pub fn ticks(self, n: usize) -> Self

Draw n evenly-spaced tick marks across the track (including both endpoints, so .ticks(5) draws 5 ticks at 0%, 25%, 50%, 75%, 100%). Pass 0 or 1 to suppress ticks.

Source

pub fn show_tick_labels(self, show: bool) -> Self

When tick marks are drawn, also render the value at each tick beneath the track. No effect without ticks.

Source

pub fn accent(self, accent: Accent) -> Self

Pick the fill colour. Default: Accent::Sky.

Source

pub fn desired_width(self, width: f32) -> Self

Override the slider width. Defaults to ui.available_width().

Source

pub fn enabled(self, enabled: bool) -> Self

Disable the widget. A disabled slider still paints its current values but ignores pointer and keyboard input. Default: enabled.

Source

pub fn id_salt(self, id_salt: impl Hash) -> Self

Salt used to derive the per-thumb interaction ids. Set this when multiple range sliders share a parent ui so their thumbs don’t collide on focus or drag state.

Trait Implementations§

Source§

impl<'a, T: Numeric> Debug for RangeSlider<'a, T>

Source§

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

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

impl<'a, T: Numeric> Widget for RangeSlider<'a, T>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for RangeSlider<'a, T>
where T: Freeze,

§

impl<'a, T> !RefUnwindSafe for RangeSlider<'a, T>

§

impl<'a, T> !Send for RangeSlider<'a, T>

§

impl<'a, T> !Sync for RangeSlider<'a, T>

§

impl<'a, T> Unpin for RangeSlider<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for RangeSlider<'a, T>
where T: UnsafeUnpin,

§

impl<'a, T> !UnwindSafe for RangeSlider<'a, T>

Blanket Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.