summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorLibravatar Sebastian Zivota <sebastian.zivota@mailbox.org>2020-06-02 20:34:13 +0200
committerLibravatar Sebastian Zivota <sebastian.zivota@mailbox.org>2020-06-11 00:18:24 +0200
commitc3643eaf6d90dc8b60c0b762200bf1f8097cdfe9 (patch)
tree6651e8db73202abf3482dedbfd9b65e28319f488 /web
parentbaa1389f71e419383429eb10ac051b1aaf0a3e26 (diff)
downloadiced-c3643eaf6d90dc8b60c0b762200bf1f8097cdfe9.tar.gz
iced-c3643eaf6d90dc8b60c0b762200bf1f8097cdfe9.tar.bz2
iced-c3643eaf6d90dc8b60c0b762200bf1f8097cdfe9.zip
Add `step` member to slider widgets
Both the native and the web slider now have a member `step` to control the least possible change of the slider's value. It defaults to 1.0 for all sliders and can be adjusted with the step method.
Diffstat (limited to 'web')
-rw-r--r--web/src/widget/slider.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/web/src/widget/slider.rs b/web/src/widget/slider.rs
index 5aa6439e..60d69798 100644
--- a/web/src/widget/slider.rs
+++ b/web/src/widget/slider.rs
@@ -16,6 +16,8 @@ use std::{ops::RangeInclusive, rc::Rc};
///
/// A [`Slider`] will try to fill the horizontal space of its container.
///
+/// The step size defaults to 1.0.
+///
/// [`Slider`]: struct.Slider.html
///
/// # Example
@@ -37,6 +39,7 @@ use std::{ops::RangeInclusive, rc::Rc};
pub struct Slider<'a, Message> {
_state: &'a mut State,
range: RangeInclusive<f32>,
+ step: f32,
value: f32,
on_change: Rc<Box<dyn Fn(f32) -> Message>>,
width: Length,
@@ -69,6 +72,7 @@ impl<'a, Message> Slider<'a, Message> {
_state: state,
value: value.max(*range.start()).min(*range.end()),
range,
+ step: 1.0,
on_change: Rc::new(Box::new(on_change)),
width: Length::Fill,
style: Default::default(),
@@ -90,6 +94,14 @@ impl<'a, Message> Slider<'a, Message> {
self.style = style.into();
self
}
+
+ /// Sets the step size of the [`Slider`].
+ ///
+ /// [`Slider`]: struct.Slider.html
+ pub fn step(mut self, step: f32) -> Self {
+ self.step = step;
+ self
+ }
}
impl<'a, Message> Widget<Message> for Slider<'a, Message>
@@ -110,15 +122,15 @@ where
let min = bumpalo::format!(in bump, "{}", start);
let max = bumpalo::format!(in bump, "{}", end);
let value = bumpalo::format!(in bump, "{}", self.value);
+ let step = bumpalo::format!(in bump, "{}", self.step);
let on_change = self.on_change.clone();
let event_bus = bus.clone();
- // TODO: Make `step` configurable
// TODO: Styling
input(bump)
.attr("type", "range")
- .attr("step", "0.01")
+ .attr("step", step.into_bump_str())
.attr("min", min.into_bump_str())
.attr("max", max.into_bump_str())
.attr("value", value.into_bump_str())