From 9991a894286a52dc81c1f8e449a64395bbe5b5fe Mon Sep 17 00:00:00 2001 From: rubik83 <45452623+rubik83@users.noreply.github.com> Date: Tue, 15 Sep 2020 12:56:50 +0200 Subject: [PATCH 1/3] fix active_progress_width formula change : let active_progress_width = bounds.width * ((value - range_start) / (range_end - range_start).max(1.0)) to : let active_progress_width = bounds.width * ((value - range_start) / (range_end - range_start).max(f32::EPSILON)).max(0.0).min(1.0) --- graphics/src/widget/progress_bar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/src/widget/progress_bar.rs b/graphics/src/widget/progress_bar.rs index 932f4fc2..4105a1aa 100644 --- a/graphics/src/widget/progress_bar.rs +++ b/graphics/src/widget/progress_bar.rs @@ -34,7 +34,7 @@ where let (range_start, range_end) = range.into_inner(); let active_progress_width = bounds.width - * ((value - range_start) / (range_end - range_start).max(1.0)); + * ((value - range_start) / (range_end - range_start).max(f32::EPSILON)).max(0.0).min(1.0); let background = Primitive::Group { primitives: vec![Primitive::Quad { From 955b62ea2deec383fe693d169dba8d35633876a3 Mon Sep 17 00:00:00 2001 From: rubik83 <45452623+rubik83@users.noreply.github.com> Date: Tue, 15 Sep 2020 13:00:38 +0200 Subject: [PATCH 2/3] fix slider handle_offset formula change : let handle_offset = (bounds.width - handle_width) * ((value - range_start) / (range_end - range_start).max(1.0)) to : let handle_offset = (bounds.width - handle_width) * ((value - range_start) / (range_end - range_start).max(f32::EPSILON)).max(0.0).min(1.0) --- graphics/src/widget/slider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/src/widget/slider.rs b/graphics/src/widget/slider.rs index 9a4af9ac..87780d38 100644 --- a/graphics/src/widget/slider.rs +++ b/graphics/src/widget/slider.rs @@ -88,7 +88,7 @@ where }; let handle_offset = (bounds.width - handle_width) - * ((value - range_start) / (range_end - range_start).max(1.0)); + * ((value - range_start) / (range_end - range_start).max(f32::EPSILON)).max(0.0).min(1.0); let handle = Primitive::Quad { bounds: Rectangle { From c23136a5df7bc4c4e7f43785088985a1b63f8daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 26 Nov 2020 03:33:08 +0100 Subject: [PATCH 3/3] Account for empty ranges in `Slider` and `ProgressBar` --- graphics/src/widget/progress_bar.rs | 9 ++++++--- graphics/src/widget/slider.rs | 12 ++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/graphics/src/widget/progress_bar.rs b/graphics/src/widget/progress_bar.rs index 4105a1aa..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(f32::EPSILON)).max(0.0).min(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 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 {