Skip to content

Commit

Permalink
Fix : take rounding into account when using Slider::trailing_fill (
Browse files Browse the repository at this point in the history
…emilk#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)
  • Loading branch information
rustbasic authored and hacknus committed Oct 30, 2024
1 parent 015e288 commit 22d0b60
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
);
}
Expand Down

0 comments on commit 22d0b60

Please sign in to comment.