From a8c0a55eb07b6691fd1b5e954812a2639246c184 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 27 Jan 2023 23:21:30 +0100 Subject: [PATCH 1/2] DragValue and Slider text is now proportional instead of monospace Control with `Style::drag_value_text_style` --- crates/egui/src/style.rs | 18 ++++++++++++++++++ crates/egui/src/widgets/drag_value.rs | 7 +++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index d90e9c1ac8f..08334cc3f7a 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -174,6 +174,9 @@ pub struct Style { /// ``` pub text_styles: BTreeMap, + /// The style to use for [`DragValue`] text. + pub drag_value_text_style: TextStyle, + /// If set, labels buttons wtc will use this to determine whether or not /// to wrap the text at the right edge of the [`Ui`] they are in. /// By default this is `None`. @@ -678,6 +681,7 @@ impl Default for Style { override_font_id: None, override_text_style: None, text_styles: default_text_styles(), + drag_value_text_style: TextStyle::Button, wrap: None, spacing: Spacing::default(), interaction: Interaction::default(), @@ -922,6 +926,7 @@ impl Style { override_font_id, override_text_style, text_styles, + drag_value_text_style, wrap: _, spacing, interaction, @@ -963,6 +968,19 @@ impl Style { }); ui.end_row(); + ui.label("Text style of DragValue:"); + crate::ComboBox::from_id_source("drag_value_text_style") + .selected_text(drag_value_text_style.to_string()) + .show_ui(ui, |ui| { + let all_text_styles = ui.style().text_styles(); + for style in all_text_styles { + let text = + crate::RichText::new(style.to_string()).text_style(style.clone()); + ui.selectable_value(drag_value_text_style, style, text); + } + }); + ui.end_row(); + ui.label("Animation duration:"); ui.add( Slider::new(animation_time, 0.0..=1.0) diff --git a/crates/egui/src/widgets/drag_value.rs b/crates/egui/src/widgets/drag_value.rs index 933a840a375..a4712a2113d 100644 --- a/crates/egui/src/widgets/drag_value.rs +++ b/crates/egui/src/widgets/drag_value.rs @@ -456,6 +456,8 @@ impl<'a> Widget for DragValue<'a> { } }; + let text_style = ui.style().drag_value_text_style.clone(); + // some clones below are redundant if AccessKit is disabled #[allow(clippy::redundant_clone)] let mut response = if is_kb_editing { @@ -467,7 +469,7 @@ impl<'a> Widget for DragValue<'a> { TextEdit::singleline(&mut value_text) .id(id) .desired_width(button_width) - .font(TextStyle::Monospace), + .font(text_style), ); let parsed_value = match custom_parser { Some(parser) => parser(&value_text), @@ -481,7 +483,8 @@ impl<'a> Widget for DragValue<'a> { response } else { let button = Button::new( - RichText::new(format!("{}{}{}", prefix, value_text.clone(), suffix)).monospace(), + RichText::new(format!("{}{}{}", prefix, value_text.clone(), suffix)) + .text_style(text_style), ) .wrap(false) .sense(Sense::click_and_drag()) From 20cb4ab661d3e1f511e71335a88c95eab81b4e04 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 27 Jan 2023 23:22:43 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fb594b6163..034124582c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG * Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)). * Improved the algorithm for picking the number of decimals to show when hovering values in the `Plot`. * Default `ComboBox` is now controlled with `Spacing::combo_width` ([#2621](https://github.com/emilk/egui/pull/2621)). +* `DragValue` and `Slider` now use the proportional font ([#2638](https://github.com/emilk/egui/pull/2638)). ### Fixed 🐛 * Trigger `PointerEvent::Released` for drags ([#2507](https://github.com/emilk/egui/pull/2507)).