Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Apply button_padding and drag_value_text_style applied in Slider., #5027

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::ops::RangeInclusive;

use crate::{
emath, epaint, lerp, pos2, remap, remap_clamp, style, style::HandleShape, vec2, Color32,
DragValue, EventFilter, Key, Label, NumExt, Pos2, Rangef, Rect, Response, Sense, TextStyle,
TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, MINUS_CHAR_STR,
DragValue, EventFilter, Key, Label, NumExt, Pos2, Rangef, Rect, Response, Sense, TextWrapMode,
Ui, Vec2, Widget, WidgetInfo, WidgetText, MINUS_CHAR_STR,
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -560,6 +560,13 @@ impl<'a> Slider<'a> {
self.range.clone()
}

fn button_padding(&self, ui: &Ui) -> f32 {
match self.orientation {
SliderOrientation::Horizontal => ui.spacing().button_padding.y,
SliderOrientation::Vertical => ui.spacing().button_padding.x,
}
}

/// For instance, `position` is the mouse position and `position_range` is the physical location of the slider on the screen.
fn value_from_position(&self, position: f32, position_range: Rangef) -> f64 {
let normalized = remap_clamp(position, position_range, 0.0..=1.0) as f64;
Expand Down Expand Up @@ -797,7 +804,7 @@ impl<'a> Slider<'a> {
SliderOrientation::Horizontal => rect.height(),
SliderOrientation::Vertical => rect.width(),
};
limit / 2.5
limit / 2.8
}

fn value_ui(&mut self, ui: &mut Ui, position_range: Rangef) -> Response {
Expand Down Expand Up @@ -855,9 +862,12 @@ impl<'a> Slider<'a> {
fn add_contents(&mut self, ui: &mut Ui) -> Response {
let old_value = self.get_value();

let button_padding = self.button_padding(ui);

let thickness = ui
.text_style_height(&TextStyle::Body)
.at_least(ui.spacing().interact_size.y);
.text_style_height(&ui.style().drag_value_text_style)
.at_least(ui.spacing().interact_size.y)
+ (button_padding * 2.0);
let mut response = self.allocate_slider_space(ui, thickness);
self.slider_ui(ui, &response);

Expand Down
Loading