From 93ed9fd468d9bd74c500c123e34cc89dcbb3fb66 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 8 Nov 2022 10:03:49 +0100 Subject: [PATCH] Only show tooltips when mouse pointer is still Revert to the old behavior by setting `style.interaction.show_tooltips_only_when_still = false`. --- CHANGELOG.md | 1 + crates/egui/src/containers/popup.rs | 12 ++++++++---- crates/egui/src/response.rs | 18 ++++++++++++------ crates/egui/src/style.rs | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b3cf0b8daa..57a3bef2bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG ### Changed 🔧 * Panels always have a separator line, but no stroke on other sides. Their spacing has also changed slightly ([#2261](https://github.com/emilk/egui/pull/2261)). +* Tooltips are only shown when mouse pointer is still ([#2263](https://github.com/emilk/egui/pull/2263)). ### Fixed 🐛 * ⚠️ BREAKING: Fix text being too small ([#2069](https://github.com/emilk/egui/pull/2069)). diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 9742ac43542..0e19ac46f88 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -6,13 +6,13 @@ use crate::*; /// Same state for all tooltips. #[derive(Clone, Debug, Default)] -pub(crate) struct MonoState { +pub(crate) struct PopupState { last_id: Option, last_size: Vec, } -impl MonoState { - fn load(ctx: &Context) -> Option { +impl PopupState { + pub fn load(ctx: &Context) -> Option { ctx.data().get_temp(Id::null()) } @@ -45,6 +45,10 @@ impl MonoState { self.last_size.extend((0..index).map(|_| Vec2::ZERO)); self.last_size.push(size); } + + pub fn is_open(ctx: &Context, id: &Id) -> bool { + Self::load(ctx).map_or(false, |state| state.last_id == Some(*id)) + } } // ---------------------------------------------------------------------------- @@ -181,7 +185,7 @@ fn show_tooltip_at_avoid_dyn<'c, R>( return None; // No good place for a tooltip :( }; - let mut state = MonoState::load(ctx).unwrap_or_default(); + let mut state = PopupState::load(ctx).unwrap_or_default(); let expected_size = state.tooltip_size(id, count); let expected_size = expected_size.unwrap_or_else(|| vec2(64.0, 32.0)); diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 5b8f067c401..fbbff6e9651 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -395,12 +395,18 @@ impl Response { return false; } - if self.ctx.style().interaction.show_tooltips_only_when_still - && !self.ctx.input().pointer.is_still() - { - // wait for mouse to stop - self.ctx.request_repaint(); - return false; + if self.ctx.style().interaction.show_tooltips_only_when_still { + // We only show the tooltip when the mouse pointer is still, + // but once shown we keep showing it until the mouse leaves the parent. + + use crate::containers::popup::PopupState; + + let is_pointer_still = self.ctx.input().pointer.is_still(); + if !is_pointer_still && !PopupState::is_open(&self.ctx, &self.id.with("__tooltip")) { + // wait for mouse to stop + self.ctx.request_repaint(); + return false; + } } // We don't want tooltips of things while we are dragging them, diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index a92e723a737..195577fa66c 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -668,7 +668,7 @@ impl Default for Interaction { Self { resize_grab_radius_side: 5.0, resize_grab_radius_corner: 10.0, - show_tooltips_only_when_still: false, + show_tooltips_only_when_still: true, } } }