pub struct PercentSlider<'a> { /* private fields */ }Expand description
A 0–100% slider whose central UI element is the percentage value itself.
let mut share = 45.0_f32;
ui.add(
PercentSlider::new(&mut share)
.label("Cache window")
.callout_fmt(|p| {
let mins = (p * 60.0 / 100.0).round() as i32;
format!("{mins} min")
}),
);Implementations§
Source§impl<'a> PercentSlider<'a>
impl<'a> PercentSlider<'a>
Sourcepub fn label(self, label: impl Into<WidgetText>) -> Self
pub fn label(self, label: impl Into<WidgetText>) -> Self
Add a small label in the top-left of the header row.
The label also names the slider for screen readers. Without one, name
the returned response with egui::Response::accessible_name, or with
egui::Response::labelled_by when a caption is drawn beside it.
Sourcepub fn accent(self, accent: Accent) -> Self
pub fn accent(self, accent: Accent) -> Self
Pick the fill colour from one of the theme accents. Default: Accent::Sky.
Sourcepub fn show_ticks(self, show: bool) -> Self
pub fn show_ticks(self, show: bool) -> Self
Show or hide the quartile tick row beneath the track. Default: true.
Sourcepub fn steps(self, n: usize) -> Self
pub fn steps(self, n: usize) -> Self
Snap to n evenly-spaced positions, including both endpoints.
steps(2) snaps to {0, 100}, steps(5) to {0, 25, 50, 75, 100},
steps(7) to seven positions whose spacing the widget computes for
you (so the awkward 100 / 6 math stays out of caller code).
When set, the tick row renders at exactly those positions and the
arrow keys jump between adjacent stops. Values below 2 are
promoted to 2. Mutually exclusive with step and
stops; calling this clears either of them.
Sourcepub fn stops(self, positions: impl IntoIterator<Item = f32>) -> Self
pub fn stops(self, positions: impl IntoIterator<Item = f32>) -> Self
Snap to an explicit, possibly non-uniform list of positions in
0.0..=100.0. Out-of-range, NaN, and duplicate values are filtered
out; the result is sorted ascending. If fewer than two valid
positions remain, falls back to [0.0, 100.0].
When set, the tick row renders at exactly these positions and the
arrow keys jump between adjacent stops. Mutually exclusive with
step and steps; calling this clears
either of them.
Sourcepub fn decimals(self, n: usize) -> Self
pub fn decimals(self, n: usize) -> Self
Number of decimal places in the headline value. Default: 0.
Sourcepub fn callout_fmt(self, fmt: impl Fn(f32) -> String + 'a) -> Self
pub fn callout_fmt(self, fmt: impl Fn(f32) -> String + 'a) -> Self
Supply a callback to format the entire drag-callout text. The
callback receives the current percentage in 0.0..=100.0 and returns
the string to render in the callout above the thumb while the user
drags. When unset, no callout is shown.
The callback has full control over the text. The widget does not prepend the percentage. Common patterns:
// Just the absolute quantity (the headline already shows the percent):
.callout_fmt(|p| format!("{} min", (p * 60.0 / 100.0).round() as i32))
// Percent and absolute together:
.callout_fmt(|p| {
let mins = (p * 60.0 / 100.0).round() as i32;
format!("{}% \u{00B7} {} min", p.round() as i32, mins)
})Sourcepub fn desired_width(self, width: f32) -> Self
pub fn desired_width(self, width: f32) -> Self
Override the slider width. Defaults to ui.available_width().
Sourcepub fn handle(self, handle: SliderHandle) -> Self
pub fn handle(self, handle: SliderHandle) -> Self
Pick the thumb shape. Default: SliderHandle::Circle. Switch to
SliderHandle::Line for a thin vertical bar instead of the standard
circular knob.
Trait Implementations§
Source§impl<'a> Debug for PercentSlider<'a>
impl<'a> Debug for PercentSlider<'a>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for PercentSlider<'a>
impl<'a> !Send for PercentSlider<'a>
impl<'a> !Sync for PercentSlider<'a>
impl<'a> !UnwindSafe for PercentSlider<'a>
impl<'a> Freeze for PercentSlider<'a>
impl<'a> Unpin for PercentSlider<'a>
impl<'a> UnsafeUnpin for PercentSlider<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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