Skip to main content

Slider

Struct Slider 

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

A horizontal numeric slider.

let mut cpu = 42.0_f32;
ui.add(Slider::new(&mut cpu, 0.0..=100.0).label("CPU limit").suffix("%"));

Implementations§

Source§

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

Source

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

Create a slider bound to value, constrained to range.

Source

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

Show a label above the slider.

Source

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

Suffix appended to the formatted 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

Supply a custom formatter for the value display. Overrides suffix and decimals.

Source

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

Hide the right-aligned value display.

Source

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

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

Source

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

Pick the fill colour from one of the theme accents. Default: Accent::Sky.

Source

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

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

Trait Implementations§

Source§

impl<'a, T: Numeric> Debug for Slider<'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 Slider<'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 Slider<'a, T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

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

§

impl<'a, T> !UnwindSafe for Slider<'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.