Skip to main content

RangeSlider

Struct RangeSlider 

Source
pub struct RangeSlider<'a> { /* private fields */ }
Available on crate feature egui only.
Expand description

Select a range of numbers with a two-handled slider.

The handles may meet but never cross. Looks and behaves like crate::Slider, but with two handles.

ui.add(egui::RangeSlider::new(&mut low, &mut high, 0.0..=100.0).text("Range"));

The default size is set by crate::style::Spacing::slider_width.

Implementations§

Source§

impl<'a> RangeSlider<'a>

Source

pub fn new<Num>( low: &'a mut Num, high: &'a mut Num, range: impl Into<RangeInclusive<Num>>, ) -> RangeSlider<'a>
where Num: Numeric,

Creates a new horizontal range slider.

The values are clamped to range, and low is clamped to high.

Source

pub fn from_get_set( range: RangeInclusive<f64>, get_set_low: impl FnMut(Option<f64>) -> f64 + 'a, get_set_high: impl FnMut(Option<f64>) -> f64 + 'a, ) -> RangeSlider<'a>

Creates a range slider over values that cannot be borrowed directly.

Source

pub fn integer(self) -> RangeSlider<'a>

Helper: equivalent to self.fixed_decimals(0).smallest_positive(1.0).step_by(1.0).

Source

pub fn text(self, text: impl Into<WidgetText>) -> RangeSlider<'a>

Show a text label next to the widget.

Source

pub fn text_color(self, text_color: Color32) -> RangeSlider<'a>

Set the color of the text shown next to the widget.

Source

pub fn min_separation<Num>(self, min_separation: Num) -> RangeSlider<'a>
where Num: Numeric,

The closest the handles may come, in values rather than points.

Default: 0.0, which lets the range collapse to nothing.

Source

pub fn orientation(self, orientation: SliderOrientation) -> RangeSlider<'a>

Which way the rail runs. Default: SliderOrientation::Horizontal.

Source

pub fn vertical(self) -> RangeSlider<'a>

Make this a vertical range slider.

Source

pub fn clamping(self, clamping: SliderClamping) -> RangeSlider<'a>

Controls when the values are clamped to the range. Default: SliderClamping::Always.

Source

pub fn smart_aim(self, smart_aim: bool) -> RangeSlider<'a>

Guide the values towards round numbers while dragging. Default: true.

Source

pub fn step_by(self, step: f64) -> RangeSlider<'a>

Set the minimal change of the values.

Value 0.0 effectively disables the feature. Default: 0.0.

Source

pub fn handle_shape(self, handle_shape: HandleShape) -> RangeSlider<'a>

Change the shape of both handles. Default: crate::style::Visuals::handle_shape.

Source

pub fn spec(self, spec: SliderSpec) -> RangeSlider<'a>

Replace how values are spread along the rail.

Source

pub fn logarithmic(self, logarithmic: bool) -> RangeSlider<'a>

Give the small values as much of the rail as the large ones. Default: false.

Source

pub fn smallest_positive(self, smallest_positive: f64) -> RangeSlider<'a>

For logarithmic sliders that includes zero: what is the smallest positive value you want to be able to select? Default: 1e-6.

Source

pub fn largest_finite(self, largest_finite: f64) -> RangeSlider<'a>

For logarithmic sliders, the largest positive value we are interested in before the slider switches to INFINITY, if that is the higher end. Default: INFINITY.

Source

pub fn drag_value(self, drag_value: DragValueSettings<'a>) -> RangeSlider<'a>

Replace every setting for the numbers beside the rail.

Source

pub fn show_value(self, show_value: bool) -> RangeSlider<'a>

Show an editable value beside each end of the rail: low before it, high after it.

Default: true.

Source

pub fn drag_value_speed(self, drag_value_speed: f64) -> RangeSlider<'a>

How much the numbers beside the rail change per point of drag.

Default: the rate the handles move at.

Source

pub fn format(self, format: ValueFormat<'a>) -> RangeSlider<'a>

Replace how the numbers beside the rail are written and read back.

Source

pub fn prefix(self, prefix: impl IntoAtoms<'a>) -> RangeSlider<'a>

Show a prefix before both numbers, e.g. “x: “.

Goes in front of any prefix already set, so .prefix("b").prefix("a") shows ab.

Source

pub fn suffix(self, suffix: impl IntoAtoms<'a>) -> RangeSlider<'a>

Add a suffix to both numbers, e.g. a unit (“°” or “ m“).

Goes after any suffix already set, so .suffix("a").suffix("b") shows ab.

Source

pub fn min_decimals(self, min_decimals: usize) -> RangeSlider<'a>

Set the minimum number of decimals to display. Default: 0.

Source

pub fn max_decimals(self, max_decimals: usize) -> RangeSlider<'a>

Set the maximum number of decimals to display.

Source

pub fn max_decimals_opt(self, max_decimals: Option<usize>) -> RangeSlider<'a>

Set the maximum number of decimals to display, or None to let the widget pick.

Values will also be rounded to this number of decimals when it is set.

Source

pub fn fixed_decimals(self, num_decimals: usize) -> RangeSlider<'a>

Show exactly this many decimals.

Source

pub fn custom_formatter( self, formatter: impl Fn(f64, RangeInclusive<usize>) -> String + 'a, ) -> RangeSlider<'a>

Set a formatter for both numbers.

Source

pub fn custom_parser( self, parser: impl Fn(&str) -> Option<f64> + 'a, ) -> RangeSlider<'a>

Set a parser for both numbers, accepting what Self::custom_formatter writes.

Source

pub fn binary(self, min_width: usize, twos_complement: bool) -> RangeSlider<'a>

Display and parse both numbers as binary integers. See ValueFormat::binary.

ui.add(egui::RangeSlider::new(&mut low, &mut high, -100..=100).binary(64, false));
Source

pub fn octal(self, min_width: usize, twos_complement: bool) -> RangeSlider<'a>

Display and parse both numbers as octal integers. See ValueFormat::octal.

ui.add(egui::RangeSlider::new(&mut low, &mut high, -100..=100).octal(22, false));
Source

pub fn hexadecimal( self, min_width: usize, twos_complement: bool, upper: bool, ) -> RangeSlider<'a>

Display and parse both numbers as hexadecimal integers. See ValueFormat::hexadecimal.

ui.add(egui::RangeSlider::new(&mut low, &mut high, -100..=100).hexadecimal(16, false, true));
Source

pub fn update_while_editing(self, update: bool) -> RangeSlider<'a>

Update the values on each key press while a number is being typed. Default: true.

Trait Implementations§

Source§

impl Widget for RangeSlider<'_>

Source§

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

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

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> !RefUnwindSafe for RangeSlider<'a>

§

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

§

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

§

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

§

impl<'a> Forget for RangeSlider<'a>

§

impl<'a> Freeze for RangeSlider<'a>
where *const dyn FnMut(Option<f64>) -> f64 + 'a is !null: Freeze, PhantomData<dyn FnMut(Option<f64>) -> f64 + 'a>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<RichText> is !null: Freeze, PhantomData<ArcInner<RichText>>: Freeze, *const ArcInner<LayoutJob> is !null: Freeze, PhantomData<ArcInner<LayoutJob>>: Freeze, *const ArcInner<Galley> is !null: Freeze, PhantomData<ArcInner<Galley>>: Freeze, PhantomData<Atom<'a>>: Freeze, *const ArcInner<dyn Fn(f64, RangeInclusive<usize>) -> String + 'a> is !null: Freeze, PhantomData<ArcInner<dyn Fn(f64, RangeInclusive<usize>) -> String + 'a>>: Freeze, *const ArcInner<dyn Fn(&str) -> Option<f64> + 'a> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&str) -> Option<f64> + 'a>>: Freeze,

§

impl<'a> Move for RangeSlider<'a>

§

impl<'a> Unpin for RangeSlider<'a>
where Box<dyn FnMut(Option<f64>) -> f64 + 'a>: Unpin, *const u8 is !null: Unpin, Arc<RichText>: Unpin, Arc<LayoutJob>: Unpin, Arc<Galley>: Unpin, NonZero<u64>: Unpin, &'a str: Unpin, String: Unpin, &'static str: Unpin, &'static [u8]: Unpin, Arc<[u8]>: Unpin, Box<dyn FnOnce(&Ui, IntoSizedArgs) -> IntoSizedResult<'static> + 'a>: Unpin, Arc<dyn Fn(&Ui, AtomPaintArgs) + 'a>: Unpin, Box<WidgetAtom<'a>>: Unpin, Box<ContainerAtom<'a>>: Unpin, Arc<dyn Fn(f64, RangeInclusive<usize>) -> String + 'a>: Unpin, Arc<dyn Fn(&str) -> Option<f64> + 'a>: Unpin,

§

impl<'a> UnsafeUnpin for RangeSlider<'a>
where *const dyn FnMut(Option<f64>) -> f64 + 'a is !null: UnsafeUnpin, PhantomData<dyn FnMut(Option<f64>) -> f64 + 'a>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<RichText> is !null: UnsafeUnpin, PhantomData<ArcInner<RichText>>: UnsafeUnpin, *const ArcInner<LayoutJob> is !null: UnsafeUnpin, PhantomData<ArcInner<LayoutJob>>: UnsafeUnpin, *const ArcInner<Galley> is !null: UnsafeUnpin, PhantomData<ArcInner<Galley>>: UnsafeUnpin, PhantomData<Atom<'a>>: UnsafeUnpin, *const ArcInner<dyn Fn(f64, RangeInclusive<usize>) -> String + 'a> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(f64, RangeInclusive<usize>) -> String + 'a>>: UnsafeUnpin, *const ArcInner<dyn Fn(&str) -> Option<f64> + 'a> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&str) -> Option<f64> + 'a>>: UnsafeUnpin,

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

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

Source§

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

Source§

fn simd_from(_simd: S, value: T) -> 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 = !

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