From 0a9e0c87a451154090b0ed75f3d25979a2a512fd Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 5 Jul 2024 11:36:26 +0200 Subject: [PATCH] Fix occational flickering of pointer-tooltips (#4788) Affects uses of `on_hover_ui_at_pointer` and `show_tooltip_at_pointer` --- crates/egui/src/containers/popup.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 37d151ba..d7fc9354 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -79,12 +79,22 @@ pub fn show_tooltip_at_pointer( add_contents: impl FnOnce(&mut Ui) -> R, ) -> Option { ctx.input(|i| i.pointer.hover_pos()).map(|pointer_pos| { - show_tooltip_at( + let allow_placing_below = true; + + // Add a small exclusion zone around the pointer to avoid tooltips + // covering what we're hovering over. + let mut exclusion_rect = Rect::from_center_size(pointer_pos, Vec2::splat(24.0)); + + // Keep the left edge of the tooltip in line with the cursor: + exclusion_rect.min.x = pointer_pos.x; + + show_tooltip_at_dyn( ctx, parent_layer, widget_id, - pointer_pos + vec2(16.0, 16.0), - add_contents, + allow_placing_below, + &exclusion_rect, + Box::new(add_contents), ) }) }