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)
This commit is contained in:
rustbasic 2024-04-21 18:49:14 +09:00 committed by GitHub
parent 690c3ba883
commit d2c4269240
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 8 deletions

View File

@ -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,
);
}