From cbb5d6aa936c7498214dba03b594fbe75dbe7488 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 5 Jun 2024 19:08:51 +0200 Subject: [PATCH] Handle tooltips so large that they cover the widget (#4623) Previously a tooltip that overlapped the original widget would case an invisible or flickering tooltip. * Closes https://github.com/emilk/egui/issues/4616 --- crates/egui/src/response.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 045b28a25a9..64b2ff19842 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -587,6 +587,17 @@ impl Response { let is_tooltip_open = self.is_tooltip_open(); if is_tooltip_open { + let (pointer_pos, pointer_vel) = self + .ctx + .input(|i| (i.pointer.hover_pos(), i.pointer.velocity())); + + if let Some(pointer_pos) = pointer_pos { + if self.rect.contains(pointer_pos) { + // Handle the case of a big tooltip that covers the widget: + return true; + } + } + let tooltip_id = crate::next_tooltip_id(&self.ctx, self.id); let layer_id = LayerId::new(Order::Tooltip, tooltip_id); @@ -603,17 +614,14 @@ impl Response { // (i.e. click links that are in it). if let Some(area) = AreaState::load(&self.ctx, tooltip_id) { let rect = area.rect(); - let pointer_in_area_or_on_the_way_there = self.ctx.input(|i| { - if let Some(pos) = i.pointer.hover_pos() { - rect.contains(pos) - || rect.intersects_ray(pos, i.pointer.velocity().normalized()) - } else { - false - } - }); - if pointer_in_area_or_on_the_way_there { - return true; + if let Some(pos) = pointer_pos { + let pointer_in_area_or_on_the_way_there = rect.contains(pos) + || rect.intersects_ray(pos, pointer_vel.normalized()); + + if pointer_in_area_or_on_the_way_there { + return true; + } } } }