diff --git a/CHANGELOG.md b/CHANGELOG.md index 67baa18d..3424a5c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added ⭐ -* Add `egui::plot::Plot` to plot some 2D data +* Add `egui::plot::Plot` to plot some 2D data. * Add `Ui::hyperlink_to(label, url)`. ### Changed 🔧 * Improve the positioning of tooltips. +* Only show tooltips if mouse is still. ## 0.9.0 - 2021-02-07 - Light Mode and much more diff --git a/egui/src/response.rs b/egui/src/response.rs index 4fa00520..253edb0e 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -190,9 +190,7 @@ impl Response { /// Show this UI if the item was hovered (i.e. a tooltip). /// If you call this multiple times the tooltips will stack underneath the previous ones. pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self { - if (self.hovered() && self.ctx.input().pointer.tooltip_pos().is_some()) - || self.ctx.memory().everything_is_visible() - { + if self.should_show_hover_ui() { crate::containers::show_tooltip_under( &self.ctx, self.id.with("__tooltip"), @@ -203,6 +201,28 @@ impl Response { self } + fn should_show_hover_ui(&self) -> bool { + if self.ctx.memory().everything_is_visible() { + true + } else if self.hovered && self.ctx.input().pointer.has_pointer() { + let show_tooltips_only_when_still = + self.ctx.style().interaction.show_tooltips_only_when_still; + if show_tooltips_only_when_still { + if self.ctx.input().pointer.is_still() { + true + } else { + // wait for mouse to stop + self.ctx.request_repaint(); + false + } + } else { + true + } + } else { + false + } + } + /// Show this text if the item was hovered (i.e. a tooltip). /// If you call this multiple times the tooltips will stack underneath the previous ones. pub fn on_hover_text(self, text: impl Into) -> Self { diff --git a/egui/src/style.rs b/egui/src/style.rs index 3b80e719..7ce8add0 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -110,6 +110,9 @@ pub struct Interaction { /// Mouse must be the close to the corner of a window to resize pub resize_grab_radius_corner: f32, + + /// If `false`, tooltips will show up anytime you hover anything, even is mouse is still moving + pub show_tooltips_only_when_still: bool, } #[derive(Clone, Debug, PartialEq)] @@ -303,6 +306,7 @@ impl Default for Interaction { Self { resize_grab_radius_side: 5.0, resize_grab_radius_corner: 10.0, + show_tooltips_only_when_still: true, } } } @@ -516,11 +520,16 @@ impl Interaction { let Self { resize_grab_radius_side, resize_grab_radius_corner, + show_tooltips_only_when_still, } = self; ui.add(Slider::f32(resize_grab_radius_side, 0.0..=20.0).text("resize_grab_radius_side")); ui.add( Slider::f32(resize_grab_radius_corner, 0.0..=20.0).text("resize_grab_radius_corner"), ); + ui.checkbox( + show_tooltips_only_when_still, + "Only show tooltips if mouse is still", + ); ui.vertical_centered(|ui| reset_button(ui, self)); }