Skip to content

Commit

Permalink
DragValue and Slider text is now proportional instead of monospace (
Browse files Browse the repository at this point in the history
emilk#2638)

* DragValue and Slider text is now proportional instead of monospace

Control with `Style::drag_value_text_style`

* Update changelog
  • Loading branch information
emilk authored and lictex committed Jan 28, 2023
1 parent ba1ae53 commit f52cab4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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)).
Expand Down
18 changes: 18 additions & 0 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ pub struct Style {
/// ```
pub text_styles: BTreeMap<TextStyle, FontId>,

/// 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`.
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -922,6 +926,7 @@ impl Style {
override_font_id,
override_text_style,
text_styles,
drag_value_text_style,
wrap: _,
spacing,
interaction,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand All @@ -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())
Expand Down

0 comments on commit f52cab4

Please sign in to comment.