pub struct Slider<M> { /* private fields */ }Expand description
A horizontal slider over min..=max.
The message carries the value itself rather than a fraction, so a setpoint reads as one:
enum Message { Setpoint(f32) }
Slider::new(16.0, 30.0, 21.5, Message::Setpoint).with_step(0.5);§Dragging keeps the pointer even when it leaves
This is the whole reason a slider belongs in a toolkit rather than in every
application. The tree already routes moves to the pressed widget wherever the
pointer goes — but it clears VisualState::PRESSED the moment the pointer
leaves the widget, because that is what makes a button’s drag-off cancel.
A slider that read its drag state from PRESSED would therefore stop tracking
at exactly the edge it most needs to keep tracking past.
So the drag is a flag of this widget’s own, set on press and cleared on release, and the pressed look comes from that flag rather than from the tree’s. A drag that runs off either end clamps and keeps following, and comes back when the pointer does.
The one thing that flag assumes is that every press is eventually followed by a release. That is the input stream’s contract, and every backend here honours it; there is no event that means “your capture was taken away”.
§Pressing the track jumps
Rather than stepping towards the press. A panel is touch-first, and a finger landing on a point of the track means go there — there is no cursor hovering to suggest anything else. It also makes the whole track a target instead of just the knob, which matters when the knob is 20 pixels wide and the finger is not.
Implementations§
Source§impl<M> Slider<M>
impl<M> Slider<M>
Sourcepub fn new(min: f32, max: f32, value: f32, message: fn(f32) -> M) -> Self
pub fn new(min: f32, max: f32, value: f32, message: fn(f32) -> M) -> Self
A slider over min..=max, starting at value.
A reversed range is put the right way round rather than refused: it is a caller’s argument order, not a state the widget has to model.
Sourcepub fn inert(min: f32, max: f32, value: f32) -> Self
pub fn inert(min: f32, max: f32, value: f32) -> Self
A slider that emits nothing, for a value the application reads rather than reacts to.
Sourcepub fn with_step(self, step: f32) -> Self
pub fn with_step(self, step: f32) -> Self
Snaps to multiples of step from min.
Off by default, because a continuous slider is what a brightness or a volume wants. A step that is zero, negative or not a number is ignored rather than dividing by it.
Sourcepub fn with_role(self, role: Role) -> Self
pub fn with_role(self, role: Role) -> Self
Sets the colour role of the filled portion and the knob.
Sourcepub const fn value(&self) -> f32
pub const fn value(&self) -> f32
The current value, always within the range and on a step if there is one.
Sourcepub fn set_value(&mut self, value: f32)
pub fn set_value(&mut self, value: f32)
Sets the value without emitting anything, clamped and snapped.
Silent for the same reason Checkbox::set_checked is: the message
reports what a person did.
Sourcepub fn update(&mut self, value: f32) -> bool
pub fn update(&mut self, value: f32) -> bool
Sets the value, reporting whether it actually changed.
Trait Implementations§
Source§impl<M> Describe for Slider<M>
impl<M> Describe for Slider<M>
Source§const DOC: &'static str = "A value in a range, dragged along a track."
const DOC: &'static str = "A value in a range, dragged along a track."
Source§const ICON: &'static Icon
const ICON: &'static Icon
Source§const PROPERTIES: &'static [Property]
const PROPERTIES: &'static [Property]
Source§impl<M: 'static> Widget<M> for Slider<M>
impl<M: 'static> Widget<M> for Slider<M>
Source§fn describe(&self) -> Option<&dyn DynDescribe>
fn describe(&self) -> Option<&dyn DynDescribe>
Source§fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
describe.Source§fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
canvas, which is already clipped to this widget’s bounds
intersected with the damage region being repainted. Read moreSource§fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
Source§fn accepts_pointer(&self) -> bool
fn accepts_pointer(&self) -> bool
true if the pointer can hit this widget. Read moreSource§fn measure(&self, ctx: &mut MeasureCtx<'_>, offered: Offer) -> Measured
fn measure(&self, ctx: &mut MeasureCtx<'_>, offered: Offer) -> Measured
Source§fn preserves_focus(&self) -> bool
fn preserves_focus(&self) -> bool
true if a press on this widget should leave focus exactly where
it is. Read moreSource§fn animate(&mut self, now_ms: u64) -> Animation
fn animate(&mut self, now_ms: u64) -> Animation
EventCtx::request_animation — and stops being called
the moment it answers Wake::Never. Read moreAuto Trait Implementations§
impl<M> Freeze for Slider<M>
impl<M> RefUnwindSafe for Slider<M>
impl<M> Send for Slider<M>
impl<M> Sync for Slider<M>
impl<M> Unpin for Slider<M>
impl<M> UnsafeUnpin for Slider<M>
impl<M> UnwindSafe for Slider<M>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynDescribe for Twhere
T: Describe,
impl<T> DynDescribe for Twhere
T: Describe,
Source§fn kind(&self) -> &'static str
fn kind(&self) -> &'static str
Describe::KIND.Source§fn properties(&self) -> &'static [Property]
fn properties(&self) -> &'static [Property]
Describe::PROPERTIES.Source§fn get_property(&self, name: &str) -> Option<Value>
fn get_property(&self, name: &str) -> Option<Value>
Describe::get.Source§fn set_property(
&mut self,
name: &str,
value: Value,
) -> Result<(), PropertyError>
fn set_property( &mut self, name: &str, value: Value, ) -> Result<(), PropertyError>
Describe::set.