Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/color_palette/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use iced::alignment;
use iced::mouse;
use iced::theme;
use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path};
use iced::widget::{Slider, column, row, text};
use iced::widget::{Slider, column, row, slider, text};
use iced::{Center, Color, Element, Fill, Font, Pixels, Point, Rectangle, Renderer, Size, Vector};

use palette::{Darken, Hsl, Lighten, ShiftHue, convert::FromColor, rgb::Rgb};
Expand Down Expand Up @@ -304,7 +304,8 @@ impl<C: ColorSpace + Copy> ColorPicker<C> {
component: f32,
update: impl Fn(f32) -> C + 'a,
) -> Slider<'a, f64, C> {
Slider::new(range, f64::from(component), move |v| update(v as f32)).step(0.01)
Slider::new(range, f64::from(component), move |v| update(v as f32))
.scale(slider::continuous())
}

row![
Expand Down
21 changes: 13 additions & 8 deletions examples/custom_quad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,20 @@ impl Example {
self.snap,
),
text!("Radius: {top_left:.2}/{top_right:.2}/{bottom_right:.2}/{bottom_left:.2}"),
slider(1.0..=200.0, top_left, Message::RadiusTopLeftChanged).step(0.01),
slider(1.0..=200.0, top_right, Message::RadiusTopRightChanged).step(0.01),
slider(1.0..=200.0, bottom_right, Message::RadiusBottomRightChanged).step(0.01),
slider(1.0..=200.0, bottom_left, Message::RadiusBottomLeftChanged).step(0.01),
slider(0.0..=10.0, self.border_width, Message::BorderWidthChanged).step(0.01),
slider(1.0..=200.0, top_left, Message::RadiusTopLeftChanged)
.scale(slider::discrete(0.01)),
slider(1.0..=200.0, top_right, Message::RadiusTopRightChanged)
.scale(slider::discrete(0.01)),
slider(1.0..=200.0, bottom_right, Message::RadiusBottomRightChanged)
.scale(slider::discrete(0.01)),
slider(1.0..=200.0, bottom_left, Message::RadiusBottomLeftChanged)
.scale(slider::discrete(0.01)),
slider(0.0..=10.0, self.border_width, Message::BorderWidthChanged)
.scale(slider::discrete(0.01)),
text!("Shadow: {sx:.2}x{sy:.2}, {sr:.2}"),
slider(-100.0..=100.0, sx, Message::ShadowXOffsetChanged).step(0.01),
slider(-100.0..=100.0, sy, Message::ShadowYOffsetChanged).step(0.01),
slider(0.0..=100.0, sr, Message::ShadowBlurRadiusChanged).step(0.01),
slider(-100.0..=100.0, sx, Message::ShadowXOffsetChanged).scale(slider::discrete(0.01)),
slider(-100.0..=100.0, sy, Message::ShadowYOffsetChanged).scale(slider::discrete(0.01)),
slider(0.0..=100.0, sr, Message::ShadowBlurRadiusChanged).scale(slider::discrete(0.01)),
toggler(self.snap)
.label("Snap to pixel grid")
.on_toggle(Message::SnapToggled),
Expand Down
8 changes: 4 additions & 4 deletions examples/custom_shader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl IcedCubes {
control(
"Size",
slider(0.1..=0.25, self.scene.size, Message::CubeSizeChanged)
.step(0.01)
.scale(slider::continuous())
.width(100),
),
checkbox(self.scene.show_depth_buffer)
Expand All @@ -88,7 +88,7 @@ impl IcedCubes {
..self.scene.light_color
})
})
.step(0.01)
.scale(slider::continuous())
.width(100)
),
control(
Expand All @@ -99,7 +99,7 @@ impl IcedCubes {
..self.scene.light_color
})
})
.step(0.01)
.scale(slider::continuous())
.width(100)
),
control(
Expand All @@ -110,7 +110,7 @@ impl IcedCubes {
..self.scene.light_color
})
})
.step(0.01)
.scale(slider::continuous())
.width(100)
)
]
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_widget/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Example {
let content = column![
circle(self.radius),
text!("Radius: {:.2}", self.radius),
slider(1.0..=100.0, self.radius, Message::RadiusChanged).step(0.01),
slider(1.0..=100.0, self.radius, Message::RadiusChanged).scale(slider::discrete(0.01)),
]
.padding(20)
.spacing(20)
Expand Down
3 changes: 2 additions & 1 deletion examples/ferris/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ impl Image {
format!("Width: {}px", self.width)
),
with_value(
slider(0.0..=1.0, self.opacity, Message::OpacityChanged).step(0.01),
slider(0.0..=1.0, self.opacity, Message::OpacityChanged)
.scale(slider::discrete(0.01)),
format!("Opacity: {:.2}", self.opacity)
),
with_value(
Expand Down
10 changes: 5 additions & 5 deletions examples/gradient/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Gradient {

let angle_picker = row![
text("Angle").width(64),
slider(Radians::RANGE, self.angle, Message::AngleChanged).step(0.01)
slider(Radians::RANGE, self.angle, Message::AngleChanged).scale(slider::continuous())
]
.spacing(8)
.padding(8)
Expand Down Expand Up @@ -114,10 +114,10 @@ impl Default for Gradient {
fn color_picker(label: &str, color: Color) -> Element<'_, Color> {
row![
text(label).width(64),
slider(0.0..=1.0, color.r, move |r| { Color { r, ..color } }).step(0.01),
slider(0.0..=1.0, color.g, move |g| { Color { g, ..color } }).step(0.01),
slider(0.0..=1.0, color.b, move |b| { Color { b, ..color } }).step(0.01),
slider(0.0..=1.0, color.a, move |a| { Color { a, ..color } }).step(0.01),
slider(0.0..=1.0, color.r, move |r| { Color { r, ..color } }).scale(slider::continuous()),
slider(0.0..=1.0, color.g, move |g| { Color { g, ..color } }).scale(slider::continuous()),
slider(0.0..=1.0, color.b, move |b| { Color { b, ..color } }).scale(slider::continuous()),
slider(0.0..=1.0, color.a, move |a| { Color { a, ..color } }).scale(slider::continuous()),
]
.spacing(8)
.padding(8)
Expand Down
6 changes: 3 additions & 3 deletions examples/integration/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ impl Controls {
..background_color
})
})
.step(0.01),
.scale(slider::continuous()),
slider(0.0..=1.0, background_color.g, move |g| {
Message::BackgroundColorChanged(Color {
g,
..background_color
})
})
.step(0.01),
.scale(slider::continuous()),
slider(0.0..=1.0, background_color.b, move |b| {
Message::BackgroundColorChanged(Color {
b,
..background_color
})
})
.step(0.01),
.scale(slider::continuous()),
]
.width(500)
.spacing(20);
Expand Down
6 changes: 4 additions & 2 deletions examples/progress_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ impl Progress {
center(
row![
bar,
vertical_slider(0.0..=100.0, self.value, Message::SliderChanged).step(0.01),
vertical_slider(0.0..=100.0, self.value, Message::SliderChanged)
.scale(slider::continuous()),
]
.spacing(20),
)
} else {
center(
column![
bar,
slider(0.0..=100.0, self.value, Message::SliderChanged).step(0.01)
slider(0.0..=100.0, self.value, Message::SliderChanged)
.scale(slider::discrete(0.01))
]
.spacing(20),
)
Expand Down
4 changes: 2 additions & 2 deletions examples/slider/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ impl Slider {
let h_slider = container(
slider(1..=100, self.value, Message::SliderChanged)
.default(50)
.shift_step(5),
.scale(slider::discrete(1).shift_step(5)),
)
.width(250);

let v_slider = container(
vertical_slider(1..=100, self.value, Message::SliderChanged)
.default(50)
.shift_step(5),
.scale(slider::discrete(1).shift_step(5)),
)
.height(200);

Expand Down
2 changes: 1 addition & 1 deletion examples/toast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl App {
"Timeout",
row![
text!("{:0>2} sec", self.timeout_secs),
slider(1.0..=30.0, self.timeout_secs as f64, Message::Timeout).step(1.0)
slider(1.0..=30.0, self.timeout_secs as f64, Message::Timeout)
]
.spacing(5)
.into()
Expand Down
1 change: 0 additions & 1 deletion examples/tour/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ fn color_slider<'a>(
slider(0.0..=1.0, f64::from(component), move |c| {
Message::TextColorChanged(update(c as f32))
})
.step(0.01)
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion examples/vectorial_text/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl VectorialText {
let slider_with_label = |label, range, value, message: fn(f32) -> _| {
column![
row![text(label), space::horizontal(), text!("{:.2}", value)],
slider(range, value, message).step(0.01)
slider(range, value, message).scale(slider::discrete(0.01))
]
.spacing(2)
};
Expand Down
2 changes: 1 addition & 1 deletion tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ where
stack![
container(
slider(range, current, on_change)
.step(10.0)
.scale(slider::discrete(10))
.width(Fill)
.height(24)
.style(|theme: &core::Theme, status| {
Expand Down
4 changes: 2 additions & 2 deletions widget/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ pub fn slider<'a, T, Message, Theme>(
on_change: impl Fn(T) -> Message + 'a,
) -> Slider<'a, T, Message, Theme>
where
T: Copy + From<u8> + std::cmp::PartialOrd,
T: Copy + std::cmp::PartialOrd + num_traits::AsPrimitive<f64> + num_traits::FromPrimitive,
Message: Clone,
Theme: slider::Catalog + 'a,
{
Expand Down Expand Up @@ -1534,7 +1534,7 @@ pub fn vertical_slider<'a, T, Message, Theme>(
on_change: impl Fn(T) -> Message + 'a,
) -> VerticalSlider<'a, T, Message, Theme>
where
T: Copy + From<u8> + std::cmp::PartialOrd,
T: Copy + std::cmp::PartialOrd + num_traits::AsPrimitive<f64> + num_traits::FromPrimitive,
Message: Clone,
Theme: vertical_slider::Catalog + 'a,
{
Expand Down
Loading
Loading