pub struct Slider { /* private fields */ }Expand description
A reactive slider.
You can set the slider to a percent value between 0 and 100.
The slider is composed of four parts. The main view, the background bar, an accent bar and a handle.
The background bar is separate from the main view because it is shortened when EdgeAlign is set to false;
Responding to events:
You can respond to events by calling the Slider::on_change_pct, and Slider::on_change_px methods on Slider and passing in a callback. Both of these callbacks are called whenever a change is effected by either clicking or by the arrow keys.
These callbacks will not be called on reactive updates, only on a mouse event or by using the arrow keys.
You can also disable event handling Decorators::disabled. If you want to use this slider as a progress bar this may be useful.
Styling:
You can use the Slider::slider_style method to get access to a SliderCustomStyle which has convenient functions with documentation for styling all of the properties of the slider.
Styling Example:
slider::Slider::new(|| 40.pct())
.slider_style(|s| {
s.edge_align(true)
.handle_radius(50.pct())
.bar_color(palette::css::BLACK)
.bar_radius(100.pct())
.accent_bar_color(palette::css::GREEN)
.accent_bar_radius(100.pct())
.accent_bar_height(100.pct())
});Implementations§
Source§impl Slider
impl Slider
Sourcepub fn new<P: Into<Pct>>(percent: impl Fn() -> P + 'static) -> Self
pub fn new<P: Into<Pct>>(percent: impl Fn() -> P + 'static) -> Self
Create a new reactive slider.
This does not automatically hook up any on_update logic.
You will need to manually call Slider::on_change_pct or Slider::on_change_px in order to respond to updates from the slider.
You might want to use the simpler constructor Slider::new_rw which will automatically hook up the on_update logic for updating a signal directly.
§Example
let percent = RwSignal::new(40.pct());
slider::Slider::new(move || percent.get())
.on_change_pct(move |new_percent| percent.set(new_percent))
.slider_style(|s| {
s.handle_radius(0)
.bar_radius(25.pct())
.accent_bar_radius(25.pct())
})
.style(|s| s.width(200));Sourcepub fn new_rw(
percent: impl SignalGet<Pct> + SignalUpdate<Pct> + Copy + 'static,
) -> Self
pub fn new_rw( percent: impl SignalGet<Pct> + SignalUpdate<Pct> + Copy + 'static, ) -> Self
Create a new reactive slider.
This automatically hooks up the on_update logic and keeps the signal up to date.
If you need more control over the getting and setting of the value you will want to use Slider::new which gives you more control but does not automatically keep a signal up to date.
§Example
let percent = RwSignal::new(40.pct());
slider::Slider::new_rw(percent)
.slider_style(|s| {
s.handle_radius(0)
.bar_radius(25.pct())
.accent_bar_radius(25.pct())
})
.style(|s| s.width(200));Sourcepub fn new_ranged(
value: impl Fn() -> f64 + 'static,
range: RangeInclusive<f64>,
) -> Self
pub fn new_ranged( value: impl Fn() -> f64 + 'static, range: RangeInclusive<f64>, ) -> Self
Create a new reactive, ranged slider.
This does not automatically hook up any on_update logic.
You will need to manually call Slider::on_change_value in order to respond to updates from the slider.
§Example
let value = RwSignal::new(-25.0);
let range = -50.0..=100.0;
slider::Slider::new_ranged(move || value.get(), range)
.step(5.0)
.on_change_value(move |new_value| value.set(new_value))
.slider_style(|s| {
s.handle_radius(0)
.bar_radius(25.pct())
.accent_bar_radius(25.pct())
})
.style(|s| s.width(200));Sourcepub fn on_change_pct(self, onchangepct: impl Fn(Pct) + 'static) -> Self
pub fn on_change_pct(self, onchangepct: impl Fn(Pct) + 'static) -> Self
Add an event handler to be run when the slider is moved.
Only one callback of pct can be set on this view. Calling it again will clear the previously set callback.
You can set Slider::on_change_px, Slider::on_change_value and on_change_pct callbacks at the same time and both will be called on change.
Sourcepub fn on_change_px(self, onchangepx: impl Fn(f64) + 'static) -> Self
pub fn on_change_px(self, onchangepx: impl Fn(f64) + 'static) -> Self
Add an event handler to be run when the slider is moved.
Only one callback of px can be set on this view. Calling it again will clear the previously set callback.
You can set Slider::on_change_pct, Slider::on_change_value and on_change_px callbacks at the same time and both will be called on change.
Sourcepub fn on_change_value(self, onchangevalue: impl Fn(f64) + 'static) -> Self
pub fn on_change_value(self, onchangevalue: impl Fn(f64) + 'static) -> Self
Add an event handler to be run when the slider is moved.
This will emit the actual value of the slider according to the current range and step.
Only one callback of value can be set on this view. Calling it again will clear the previously set callback.
You can set Slider::on_change_pct, Slider::on_change_px and on_change_value callbacks at the same time and both will be called on change.
Sourcepub fn on_hover(self, onhover: impl Fn(Pct) + 'static) -> Self
pub fn on_hover(self, onhover: impl Fn(Pct) + 'static) -> Self
Add an event handler to be run when the mouse hovers over the slider.
The callback receives the percentage value at the current hover position. Only one hover callback can be set on this view. Calling it again will clear the previously set callback.
Sourcepub fn slider_style(
self,
style: impl Fn(SliderCustomStyle) -> SliderCustomStyle + 'static,
) -> Self
pub fn slider_style( self, style: impl Fn(SliderCustomStyle) -> SliderCustomStyle + 'static, ) -> Self
Sets the custom style properties of the Slider.
Trait Implementations§
Source§impl CustomStylable<SliderCustomStyle> for Slider
impl CustomStylable<SliderCustomStyle> for Slider
Source§impl View for Slider
impl View for Slider
fn id(&self) -> ViewId
Source§fn update(&mut self, _cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
fn update(&mut self, _cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
View’s Id handle Read morefn event_before_children( &mut self, cx: &mut EventCx<'_>, event: &Event, ) -> EventPropagation
Source§fn style_pass(&mut self, cx: &mut StyleCx<'_>)
fn style_pass(&mut self, cx: &mut StyleCx<'_>)
Source§fn compute_layout(&mut self, _cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
fn compute_layout(&mut self, _cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
Source§fn paint(&mut self, cx: &mut PaintCx<'_>)
fn paint(&mut self, cx: &mut PaintCx<'_>)
View-specific implementation. Will be called in PaintCx::paint_view.
Usually you’ll call paint_view for every child view. But you might also draw text, adjust the offset, clip
or draw text.fn view_style(&self) -> Option<Style>
fn view_class(&self) -> Option<StyleClassRef>
fn debug_name(&self) -> Cow<'static, str>
Source§fn layout(&mut self, cx: &mut LayoutCx<'_>) -> NodeId
fn layout(&mut self, cx: &mut LayoutCx<'_>) -> NodeId
LayoutCx::layout_node. Read morefn event_after_children( &mut self, cx: &mut EventCx<'_>, event: &Event, ) -> EventPropagation
Auto Trait Implementations§
impl Freeze for Slider
impl !RefUnwindSafe for Slider
impl !Send for Slider
impl !Sync for Slider
impl Unpin for Slider
impl !UnwindSafe for Slider
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> ContainerExt for Twhere
T: IntoView + 'static,
impl<T> ContainerExt for Twhere
T: IntoView + 'static,
Source§impl<T> Decorators for Twhere
T: IntoView,
impl<T> Decorators for Twhere
T: IntoView,
Source§fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
Source§fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
Source§fn debug_name_if<S: Into<String>>(
self,
apply: impl Fn() -> bool + 'static,
name: impl Fn() -> S + 'static,
) -> Self::Intermediate
fn debug_name_if<S: Into<String>>( self, apply: impl Fn() -> bool + 'static, name: impl Fn() -> S + 'static, ) -> Self::Intermediate
Source§fn dragging_style(
self,
style: impl Fn(Style) -> Style + 'static,
) -> Self::Intermediate
fn dragging_style( self, style: impl Fn(Style) -> Style + 'static, ) -> Self::Intermediate
Source§fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Source§fn class_if<C: StyleClass>(
self,
apply: impl Fn() -> bool + 'static,
_class: C,
) -> Self::Intermediate
fn class_if<C: StyleClass>( self, apply: impl Fn() -> bool + 'static, _class: C, ) -> Self::Intermediate
Source§fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Style::focusable insteadSource§fn disable_default_event(
self,
disable: impl Fn() -> (EventListener, bool) + 'static,
) -> Self::Intermediate
fn disable_default_event( self, disable: impl Fn() -> (EventListener, bool) + 'static, ) -> Self::Intermediate
Source§fn draggable(self) -> Self::Intermediate
fn draggable(self) -> Self::Intermediate
Style::draggable directly insteadSource§fn disabled(
self,
disabled_fn: impl Fn() -> bool + 'static,
) -> Self::Intermediate
fn disabled( self, disabled_fn: impl Fn() -> bool + 'static, ) -> Self::Intermediate
Style::set_disabled directly insteadSource§fn on_event(
self,
listener: EventListener,
action: impl FnMut(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_event( self, listener: EventListener, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener.Source§fn on_key_down(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_key_down( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
Source§fn on_key_up(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_key_up( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
Source§fn on_event_cont(
self,
listener: EventListener,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_event_cont( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_event_stop(
self,
listener: EventListener,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_event_stop( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_click(
self,
action: impl FnMut(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_click( self, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::Click.Source§fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::Intermediate
fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::Intermediate
EventListener::Click. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_click_stop(
self,
action: impl FnMut(&Event) + 'static,
) -> Self::Intermediate
fn on_click_stop( self, action: impl FnMut(&Event) + 'static, ) -> Self::Intermediate
EventListener::Click. This event will be handled with
the given handler and the event will stop propagating.Source§fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
Source§fn on_double_click(
self,
action: impl Fn(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_double_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::DoubleClickSource§fn on_double_click_cont(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_double_click_cont( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::DoubleClick. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_double_click_stop(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_double_click_stop( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::DoubleClick. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_secondary_click(
self,
action: impl Fn(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_secondary_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.Source§fn on_secondary_click_cont(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_secondary_click_cont( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will continue propagating.Source§fn on_secondary_click_stop(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_secondary_click_stop( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will stop propagating.Source§fn on_resize(self, action: impl Fn(Rect) + 'static) -> Self::Intermediate
fn on_resize(self, action: impl Fn(Rect) + 'static) -> Self::Intermediate
Source§fn on_move(self, action: impl Fn(Point) + 'static) -> Self::Intermediate
fn on_move(self, action: impl Fn(Point) + 'static) -> Self::Intermediate
Source§fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
Source§fn animation(
self,
animation: impl Fn(Animation) -> Animation + 'static,
) -> Self::Intermediate
fn animation( self, animation: impl Fn(Animation) -> Animation + 'static, ) -> Self::Intermediate
Source§fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Source§fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Source§fn window_scale(
self,
scale_fn: impl Fn() -> f64 + 'static,
) -> Self::Intermediate
fn window_scale( self, scale_fn: impl Fn() -> f64 + 'static, ) -> Self::Intermediate
Source§fn window_title(
self,
title_fn: impl Fn() -> String + 'static,
) -> Self::Intermediate
fn window_title( self, title_fn: impl Fn() -> String + 'static, ) -> Self::Intermediate
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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