From 7e2c65a82ae561ca48615de75d86a3f1d3c6a5c4 Mon Sep 17 00:00:00 2001 From: YgorSouza <43298013+YgorSouza@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:16:38 +0100 Subject: [PATCH] Fix upside down slider in the vertical orientation (#3424) --- crates/egui/src/widgets/slider.rs | 4 +++- crates/emath/src/range.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/widgets/slider.rs b/crates/egui/src/widgets/slider.rs index 72bceb32720..182019b95dc 100644 --- a/crates/egui/src/widgets/slider.rs +++ b/crates/egui/src/widgets/slider.rs @@ -703,7 +703,9 @@ impl<'a> Slider<'a> { let handle_radius = self.handle_radius(rect); match self.orientation { SliderOrientation::Horizontal => rect.x_range().shrink(handle_radius), - SliderOrientation::Vertical => rect.y_range().shrink(handle_radius), + // The vertical case has to be flipped because the largest slider value maps to the + // lowest y value (which is at the top) + SliderOrientation::Vertical => rect.y_range().shrink(handle_radius).flip(), } } diff --git a/crates/emath/src/range.rs b/crates/emath/src/range.rs index b7b975c4586..6de7b2a099f 100644 --- a/crates/emath/src/range.rs +++ b/crates/emath/src/range.rs @@ -97,6 +97,16 @@ impl Rangef { } } + /// Flip the min and the max + #[inline] + #[must_use] + pub fn flip(self) -> Self { + Self { + min: self.max, + max: self.min, + } + } + /// The overlap of two ranges, i.e. the range that is contained by both. /// /// If the ranges do not overlap, returns a range with `span() < 0.0`.