From d2c426924039fbd8b73be51dea01a5db0911238c Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 21 Apr 2024 18:49:14 +0900 Subject: [PATCH] Fix : take `rounding` into account when using `Slider::trailing_fill` (#4308) Handles `rounding` when doing trailing_fill on the rail of `Slider`. We can see this by setting the rounding to around 8.0 ``` ui.visuals_mut().widgets.inactive.rounding = Rounding::same(8.0); ``` Before : There is a little bit of blue painted on the left end. ![20240404-2](https://github.com/emilk/egui/assets/127506429/aa70104c-0733-41c6-8e78-c3e69eb45204) After : Fix ![20240404-3](https://github.com/emilk/egui/assets/127506429/c2452fcb-48fd-4b2a-9f1a-02a3bf763ed1) --- crates/egui/src/widgets/slider.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/egui/src/widgets/slider.rs b/crates/egui/src/widgets/slider.rs index a428fb7d..f303464a 100644 --- a/crates/egui/src/widgets/slider.rs +++ b/crates/egui/src/widgets/slider.rs @@ -686,12 +686,10 @@ impl<'a> Slider<'a> { let rail_radius = (spacing.slider_rail_height / 2.0).at_least(0.0); let rail_rect = self.rail_rect(rect, rail_radius); + let rounding = widget_visuals.inactive.rounding; - ui.painter().rect_filled( - rail_rect, - widget_visuals.inactive.rounding, - widget_visuals.inactive.bg_fill, - ); + ui.painter() + .rect_filled(rail_rect, rounding, widget_visuals.inactive.bg_fill); let position_1d = self.position_from_value(value, position_range); let center = self.marker_center(position_1d, &rail_rect); @@ -707,13 +705,17 @@ impl<'a> Slider<'a> { // The trailing rect has to be drawn differently depending on the orientation. match self.orientation { - SliderOrientation::Vertical => trailing_rail_rect.min.y = center.y, - SliderOrientation::Horizontal => trailing_rail_rect.max.x = center.x, + SliderOrientation::Horizontal => { + trailing_rail_rect.max.x = center.x + rounding.nw; + } + SliderOrientation::Vertical => { + trailing_rail_rect.min.y = center.y - rounding.se; + } }; ui.painter().rect_filled( trailing_rail_rect, - widget_visuals.inactive.rounding, + rounding, ui.visuals().selection.bg_fill, ); }