diff options
author | 2020-11-26 03:33:08 +0100 | |
---|---|---|
committer | 2020-11-26 03:33:08 +0100 | |
commit | c23136a5df7bc4c4e7f43785088985a1b63f8daf (patch) | |
tree | 1d91428a1b8ec50ff9974963a1c42df2f5a34946 /graphics/src/widget/slider.rs | |
parent | 955b62ea2deec383fe693d169dba8d35633876a3 (diff) | |
download | iced-c23136a5df7bc4c4e7f43785088985a1b63f8daf.tar.gz iced-c23136a5df7bc4c4e7f43785088985a1b63f8daf.tar.bz2 iced-c23136a5df7bc4c4e7f43785088985a1b63f8daf.zip |
Account for empty ranges in `Slider` and `ProgressBar`
Diffstat (limited to 'graphics/src/widget/slider.rs')
-rw-r--r-- | graphics/src/widget/slider.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/graphics/src/widget/slider.rs b/graphics/src/widget/slider.rs index 87780d38..aeceec3f 100644 --- a/graphics/src/widget/slider.rs +++ b/graphics/src/widget/slider.rs @@ -72,8 +72,6 @@ where }, ); - let (range_start, range_end) = range.into_inner(); - let (handle_width, handle_height, handle_border_radius) = match style .handle .shape @@ -87,8 +85,14 @@ where } => (f32::from(width), f32::from(bounds.height), border_radius), }; - let handle_offset = (bounds.width - handle_width) - * ((value - range_start) / (range_end - range_start).max(f32::EPSILON)).max(0.0).min(1.0); + let (range_start, range_end) = range.into_inner(); + + let handle_offset = if range_start >= range_end { + 0.0 + } else { + (bounds.width - handle_width) * (value - range_start) + / (range_end - range_start) + }; let handle = Primitive::Quad { bounds: Rectangle { |