summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-11-26 03:51:07 +0100
committerLibravatar GitHub <noreply@github.com>2020-11-26 03:51:07 +0100
commit50a1f78996bb3c31e37624a59b54387ace2662a1 (patch)
tree1d91428a1b8ec50ff9974963a1c42df2f5a34946
parent1f7e8b7f3d1804c39c8e0934b25f3ef178de269c (diff)
parentc23136a5df7bc4c4e7f43785088985a1b63f8daf (diff)
downloadiced-50a1f78996bb3c31e37624a59b54387ace2662a1.tar.gz
iced-50a1f78996bb3c31e37624a59b54387ace2662a1.tar.bz2
iced-50a1f78996bb3c31e37624a59b54387ace2662a1.zip
Merge pull request #527 from rubik83/master
Account for empty ranges in `Slider` and `ProgressBar`
-rw-r--r--graphics/src/widget/progress_bar.rs9
-rw-r--r--graphics/src/widget/slider.rs12
2 files changed, 14 insertions, 7 deletions
diff --git a/graphics/src/widget/progress_bar.rs b/graphics/src/widget/progress_bar.rs
index 932f4fc2..32ee42c6 100644
--- a/graphics/src/widget/progress_bar.rs
+++ b/graphics/src/widget/progress_bar.rs
@@ -31,10 +31,13 @@ where
style_sheet: &Self::Style,
) -> Self::Output {
let style = style_sheet.style();
-
let (range_start, range_end) = range.into_inner();
- let active_progress_width = bounds.width
- * ((value - range_start) / (range_end - range_start).max(1.0));
+
+ let active_progress_width = if range_start >= range_end {
+ 0.0
+ } else {
+ bounds.width * (value - range_start) / (range_end - range_start)
+ };
let background = Primitive::Group {
primitives: vec![Primitive::Quad {
diff --git a/graphics/src/widget/slider.rs b/graphics/src/widget/slider.rs
index 9a4af9ac..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(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 {