Skip to content

Commit

Permalink
Fix upside down slider in the vertical orientation (#3424)
Browse files Browse the repository at this point in the history
  • Loading branch information
YgorSouza authored Nov 10, 2023
1 parent e9f92fe commit 7e2c65a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down
10 changes: 10 additions & 0 deletions crates/emath/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 7e2c65a

Please sign in to comment.