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
This commit is contained in:
parent
f2b6edd6db
commit
67bf716b0e
5 changed files with 28 additions and 8 deletions
|
@ -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.
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue