Adjustable Slider rail height (#4092)
Adjustable Slider rail height  --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
8ca270e78e
commit
861a1b6225
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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| {
|
||||
|
|
|
|||
Loading…
Reference in New Issue