Adjustable Slider rail height (#4092)

Adjustable Slider rail height 


![explain20240312-2](https://github.com/emilk/egui/assets/127506429/d5edfe10-8191-44ed-8567-d9d2127ce4b8)

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
rustbasic 2024-03-21 18:48:40 +09:00 committed by GitHub
parent 8ca270e78e
commit 861a1b6225
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 10 deletions

View File

@ -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");

View File

@ -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| {