From 67bf716b0efc0f50e2bf5553ac54a892f29f98e4 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 12 Sep 2021 23:05:23 +0200 Subject: [PATCH] Hide DragValue tooltips unless user set Style::explanation_tooltips (#708) * Hide DragValue tooltips unless user set Style::explanation_tooltips Closes https://github.com/emilk/egui/issues/548 Closes https://github.com/emilk/egui/pull/704 * Silence drag_angle_tau tooltip too --- CHANGELOG.md | 1 + egui/src/style.rs | 12 ++++++++++++ egui/src/ui.rs | 9 ++++++--- egui/src/widgets/color_picker.rs | 6 ++++-- egui/src/widgets/drag_value.rs | 8 +++++--- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe9b93ad..ed0f604c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [ * Deprecated: `max_rect_finite`, `available_size_before_wrap_finite` and `available_rect_before_wrap_finite`. * `Painter`/`Fonts`: text layout now expect color when creating a `Galley`. You may override that color with `Painter::galley_with_color`. * MSRV (Minimum Supported Rust Version) is now `1.54.0`. +* By default, `DragValue`:s no longer show a tooltip when hovered. Change with `Style::explanation_tooltips`. ### Fixed 🐛 * Fix wrongly sized multiline `TextEdit` in justified layouts. diff --git a/egui/src/style.rs b/egui/src/style.rs index f35687d4..bd4c3637 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -47,6 +47,11 @@ pub struct Style { /// Options to help debug why egui behaves strangely. pub debug: DebugOptions, + + /// Show tooltips explaining `DragValue`:s etc when hovered. + /// + /// This only affects a few egui widgets. + pub explanation_tooltips: bool, } impl Style { @@ -361,6 +366,7 @@ impl Default for Style { visuals: Visuals::default(), animation_time: 1.0 / 12.0, debug: Default::default(), + explanation_tooltips: false, } } } @@ -566,6 +572,7 @@ impl Style { visuals, animation_time, debug, + explanation_tooltips, } = self; visuals.light_dark_radio_buttons(ui); @@ -625,6 +632,11 @@ impl Style { ui.collapsing("🎨 Visuals", |ui| visuals.ui(ui)); ui.collapsing("🐛 Debug", |ui| debug.ui(ui)); + ui.checkbox(explanation_tooltips, "Explanation tooltips") + .on_hover_text( + "Show explanatory text when hovering DragValue:s and other egui widgets", + ); + ui.vertical_centered(|ui| reset_button(ui, self)); } } diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 1de9032e..7d7f7d28 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -1144,9 +1144,12 @@ impl Ui { use std::f32::consts::TAU; let mut taus = *radians / TAU; - let mut response = self - .add(DragValue::new(&mut taus).speed(0.01).suffix("τ")) - .on_hover_text("1τ = one turn, 0.5τ = half a turn, etc. 0.25τ = 90°"); + let mut response = self.add(DragValue::new(&mut taus).speed(0.01).suffix("τ")); + + if self.style().explanation_tooltips { + response = + response.on_hover_text("1τ = one turn, 0.5τ = half a turn, etc. 0.25τ = 90°"); + } // only touch `*radians` if we actually changed the value if taus != *radians / TAU { diff --git a/egui/src/widgets/color_picker.rs b/egui/src/widgets/color_picker.rs index 2babad70..3cd2456c 100644 --- a/egui/src/widgets/color_picker.rs +++ b/egui/src/widgets/color_picker.rs @@ -337,8 +337,10 @@ fn color_picker_hsva_2d(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> bool { pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Response { let pupup_id = ui.auto_id_with("popup"); let open = ui.memory().is_popup_open(pupup_id); - let mut button_response = - color_button(ui, (*hsva).into(), open).on_hover_text("Click to edit color"); + let mut button_response = color_button(ui, (*hsva).into(), open); + if ui.style().explanation_tooltips { + button_response = button_response.on_hover_text("Click to edit color"); + } if button_response.clicked() { ui.memory().toggle_popup(pupup_id); diff --git a/egui/src/widgets/drag_value.rs b/egui/src/widgets/drag_value.rs index 850a5490..cecfac11 100644 --- a/egui/src/widgets/drag_value.rs +++ b/egui/src/widgets/drag_value.rs @@ -215,14 +215,16 @@ impl<'a> Widget for DragValue<'a> { .min_size(ui.spacing().interact_size); // TODO: find some more generic solution to this let response = ui.add(button); - let response = response - .on_hover_cursor(CursorIcon::ResizeHorizontal) - .on_hover_text(format!( + let mut response = response.on_hover_cursor(CursorIcon::ResizeHorizontal); + + if ui.style().explanation_tooltips { + response = response .on_hover_text(format!( "{}{}{}\nDrag to edit or click to enter a value.\nPress 'Shift' while dragging for better control.", prefix, value as f32, // Show full precision value on-hover. TODO: figure out f64 vs f32 suffix )); + } if response.clicked() { ui.memory().request_focus(kb_edit_id);