Skip to content

Commit 9ad72a4

Browse files
emilkhacknus
authored andcommitted
Fix occational flickering of pointer-tooltips (emilk#4788)
Affects uses of `on_hover_ui_at_pointer` and `show_tooltip_at_pointer`
1 parent e83ee79 commit 9ad72a4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

crates/egui/src/containers/popup.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,22 @@ pub fn show_tooltip_at_pointer<R>(
7979
add_contents: impl FnOnce(&mut Ui) -> R,
8080
) -> Option<R> {
8181
ctx.input(|i| i.pointer.hover_pos()).map(|pointer_pos| {
82-
show_tooltip_at(
82+
let allow_placing_below = true;
83+
84+
// Add a small exclusion zone around the pointer to avoid tooltips
85+
// covering what we're hovering over.
86+
let mut exclusion_rect = Rect::from_center_size(pointer_pos, Vec2::splat(24.0));
87+
88+
// Keep the left edge of the tooltip in line with the cursor:
89+
exclusion_rect.min.x = pointer_pos.x;
90+
91+
show_tooltip_at_dyn(
8392
ctx,
8493
parent_layer,
8594
widget_id,
86-
pointer_pos + vec2(16.0, 16.0),
87-
add_contents,
95+
allow_placing_below,
96+
&exclusion_rect,
97+
Box::new(add_contents),
8898
)
8999
})
90100
}

0 commit comments

Comments
 (0)