From 2afc43c0ecc1db34f6038525b6135c94cf7d9355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Pakalns?= Date: Tue, 9 Sep 2025 12:21:54 +0300 Subject: [PATCH] Support on hover tooltip that is noninteractable even with interactable content (#5543) --- crates/egui/src/containers/tooltip.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/egui/src/containers/tooltip.rs b/crates/egui/src/containers/tooltip.rs index 99bc95d5..682b11fd 100644 --- a/crates/egui/src/containers/tooltip.rs +++ b/crates/egui/src/containers/tooltip.rs @@ -72,7 +72,7 @@ impl Tooltip<'_> { let mut tooltip = Self::for_widget(response); tooltip.popup = tooltip .popup - .open(response.enabled() && Self::should_show_tooltip(response)); + .open(response.enabled() && Self::should_show_tooltip(response, true)); tooltip } @@ -81,7 +81,7 @@ impl Tooltip<'_> { let mut tooltip = Self::for_widget(response); tooltip.popup = tooltip .popup - .open(!response.enabled() && Self::should_show_tooltip(response)); + .open(!response.enabled() && Self::should_show_tooltip(response, true)); tooltip } @@ -211,7 +211,10 @@ impl Tooltip<'_> { } /// Should we show a tooltip for this response? - pub fn should_show_tooltip(response: &Response) -> bool { + /// + /// Argument `allow_interactive_tooltip` controls whether mouse can interact with tooltip that + /// contains interactive widgets + pub fn should_show_tooltip(response: &Response, allow_interactive_tooltip: bool) -> bool { if response.ctx.memory(|mem| mem.everything_is_visible()) { return true; } @@ -264,12 +267,13 @@ impl Tooltip<'_> { let tooltip_id = Self::next_tooltip_id(&response.ctx, response.id); let tooltip_layer_id = LayerId::new(Order::Tooltip, tooltip_id); - let tooltip_has_interactive_widget = response.ctx.viewport(|vp| { - vp.prev_pass - .widgets - .get_layer(tooltip_layer_id) - .any(|w| w.enabled && w.sense.interactive()) - }); + let tooltip_has_interactive_widget = allow_interactive_tooltip + && response.ctx.viewport(|vp| { + vp.prev_pass + .widgets + .get_layer(tooltip_layer_id) + .any(|w| w.enabled && w.sense.interactive()) + }); if tooltip_has_interactive_widget { // We keep the tooltip open if hovered,