Skip to main content

Slider

Struct Slider 

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

A slider over an f64.

Need (input): a slider over a number.

Implementations§

Source§

impl<'a> Slider<'a>

Source

pub fn new(value: &'a mut f64, label: &str, soft: RangeInclusive<f64>) -> Self

A slider spanning soft, which is also its hard range until Slider::hard widens it.

Source

pub fn from_descriptor(value: &'a mut f64, d: &Descriptor) -> Self

From a value descriptor: its label, ranges, steps, unit, precision, display scale and default.

Source

pub fn hard(self, hard: RangeInclusive<f64>) -> Self

The range a typed value may reach (it always holds the soft range).

Source

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

The step of arrows and the wheel; also sets the precision.

Source

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

The coarse step (Shift, Page Up and Page Down).

Source

pub fn unit(self, unit: &str) -> Self

Shown after the value (EV, %).

Source

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

Digits after the decimal separator.

Source

pub fn display_scale(self, scale: f64) -> Self

Shown and typed as value * scale (a fraction as a percentage: 100).

Source

pub fn integer(self) -> Self

Whole numbers only.

Source

pub fn signed(self) -> Self

A plus sign before positive values (+1.50 EV).

Source

pub fn logarithmic(self) -> Self

A logarithmic bar (Curve::Logarithmic).

Source

pub fn gradient(self, gradient: Gradient) -> Self

The track painted with a gradient (hue, temperature) along the bar.

Source

pub fn state(self, state: FieldState) -> Self

The field’s state, drawn and announced as every field’s (crate::field): a read-only slider takes the focus and refuses changes, a disabled one is greyed and skipped by Tab, with its reason as the tooltip.

Source

pub fn ramp(self, min: impl Into<RampColor>, max: impl Into<RampColor>) -> Self

A colour for the minimum and one for the maximum, the value drawn in the colour between them, blended in Oklab over the soft range (Ramp): a token path ("danger") or a Color32 each. Drawn in RampMode::Value unless ramp_track says otherwise; a high-contrast theme draws the theme’s own fill instead.

Source

pub fn ramp_stops(self, stops: &[(f32, RampColor)]) -> Self

A colour ramp through stops (place, colour), places from 0 (the soft start) to 1 (its end): for hue-like scales.

Source

pub fn ramp_with(self, ramp: Ramp) -> Self

A colour ramp built beforehand.

Source

pub fn ramp_track(self) -> Self

The ramp across the whole track, the value marked on it by the thumb or the pointer (RampMode::Track), so the scale reads before a touch; nothing without a ramp.

Source

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

What a double click goes back to.

Source

pub fn vertical(self) -> Self

A vertical slider, as a mixer’s fader: up is more. The same gestures along the other axis (a drag up does what a drag right does on a horizontal bar; Up and Right step up), the value at the top, the label at the bottom, under the track. It has no quad button.

Source

pub fn size(self, size: Vec2) -> Self

Its size, in points: the room it fills (a slot). By default a horizontal slider takes the width available (at least MIN_WIDTH) and a row’s height; a vertical one is VERTICAL_LENGTH high and a row and a half wide.

Source

pub fn compact(self) -> Self

The compact representation: the value alone, the label in the tooltip (and still the bar’s name for assistive technologies). A slider too narrow for its label and value turns compact by itself, and drops the unit when even the value does not fit.

Source

pub fn scrub(self) -> Self

The scrub field: the label and the value in a plain field, with no fill and no thumb, for a dense row (a HUD, a property sheet) where the value matters more than where it sits in its range. The slider’s gestures, keys, typed entry, menu, history and accessibility stay: a drag along the field scrubs the value over the soft range, whatever the field’s width, or at a set speed with Slider::travel. Too narrow for its label, it shows the value alone, as Slider::compact does. Horizontal only: a vertical slider keeps its track.

Experimental: may change in any release (docs/stability.md).
Source

pub fn travel(self, points: f32) -> Self

Points of drag over the soft range, whatever the bar’s length: a scrub field that moves at a set speed (a value’s sensitivity, its soft range over so many points) rather than across its width. By default the bar’s length; the fine and coarse modifiers still scale it. As Knob::travel.

Experimental: may change in any release (docs/stability.md).
Source

pub fn menu(self, on: bool) -> Self

Whether a right click (or the context menu key) opens the value’s menu: “Type a value”, and “Reset” with a default. On by default; off for a host that gives the slider a menu of its own (its “Type a value” item calls request_typed_entry).

Source

pub fn on_change(self, hook: impl FnMut(&Change) -> Verdict + 'a) -> Self

Sees every change before it is written (module docs, “Hooks”).

Source

pub fn quad(self, icon: Icon, label: &str) -> Self

A quad button at the end of the bar (a colour picker): its click is in SliderOutput::quad_clicked. label names it.

Source

pub fn quad_toggle(self, icon: Icon, label: &str, on: &'a mut bool) -> Self

A quad button toggling on (an effect on or off), lit when on.

Source

pub fn show(self, ui: &mut Ui) -> SliderOutput

Draws the slider; says what changed.

Trait Implementations§

Source§

impl<'a> Debug for Slider<'a>

Source§

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

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

impl Widget for Slider<'_>

Source§

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

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

fn boxed<'a>(self) -> Box<dyn FnOnce(&mut Ui) -> Response + 'a>
where Self: Sized + 'a,

Box this widget for dynamic dispatch.

Auto Trait Implementations§

§

impl<'a> Freeze for Slider<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for Slider<'a>

§

impl<'a> UnsafeUnpin for Slider<'a>

§

impl<'a> !UnwindSafe for Slider<'a>

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

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

§

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

§

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.
§

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

§

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

§

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