diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index a5b19e14..ac37f6eb 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -281,6 +281,9 @@ pub struct Spacing { /// Default width of a [`Slider`]. pub slider_width: f32, + /// Default rail height of a [`Slider`]. + pub slider_rail_height: f32, + /// Default (minimum) width of a [`ComboBox`](crate::ComboBox). pub combo_width: f32, @@ -1224,6 +1227,7 @@ impl Default for Spacing { indent: 18.0, // match checkbox/radio-button with `button_padding.x + icon_width + icon_spacing` interact_size: vec2(40.0, 18.0), slider_width: 100.0, + slider_rail_height: 8.0, combo_width: 100.0, text_edit_width: 280.0, icon_width: 14.0, @@ -1573,6 +1577,7 @@ impl Spacing { indent, interact_size, slider_width, + slider_rail_height, combo_width, text_edit_width, icon_width, @@ -1601,6 +1606,10 @@ impl Spacing { ui.add(DragValue::new(slider_width).clamp_range(0.0..=1000.0)); ui.label("Slider width"); }); + ui.horizontal(|ui| { + ui.add(DragValue::new(slider_rail_height).clamp_range(0.0..=50.0)); + ui.label("Slider rail height"); + }); ui.horizontal(|ui| { ui.add(DragValue::new(combo_width).clamp_range(0.0..=1000.0)); ui.label("ComboBox width"); diff --git a/crates/egui/src/widgets/slider.rs b/crates/egui/src/widgets/slider.rs index 431dd6e5..c5c60b92 100644 --- a/crates/egui/src/widgets/slider.rs +++ b/crates/egui/src/widgets/slider.rs @@ -680,11 +680,12 @@ impl<'a> Slider<'a> { if ui.is_rect_visible(response.rect) { let value = self.get_value(); - let rail_radius = ui.painter().round_to_pixel(self.rail_radius_limit(rect)); - let rail_rect = self.rail_rect(rect, rail_radius); - let visuals = ui.style().interact(response); let widget_visuals = &ui.visuals().widgets; + let spacing = &ui.style().spacing; + + let rail_radius = (spacing.slider_rail_height / 2.0).at_least(0.0); + let rail_rect = self.rail_rect(rect, rail_radius); ui.painter().rect_filled( rail_rect, @@ -800,13 +801,6 @@ impl<'a> Slider<'a> { limit / 2.5 } - fn rail_radius_limit(&self, rect: &Rect) -> f32 { - match self.orientation { - SliderOrientation::Horizontal => (rect.height() / 4.0).at_least(2.0), - SliderOrientation::Vertical => (rect.width() / 4.0).at_least(2.0), - } - } - fn value_ui(&mut self, ui: &mut Ui, position_range: Rangef) -> Response { // If [`DragValue`] is controlled from the keyboard and `step` is defined, set speed to `step` let change = ui.input(|input| {