diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 536979359da..b3b2f55a314 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -125,9 +125,10 @@ fn show_tooltip_at_dyn<'c, R>( let mut state = ctx.frame_state_mut(|fs| { // Remember that this is the widget showing the tooltip: - fs.tooltips - .per_layer_tooltip_widget - .insert(parent_layer, widget_id); + fs.layers + .entry(parent_layer) + .or_default() + .widget_with_tooltip = Some(widget_id); fs.tooltips .widget_tooltips diff --git a/crates/egui/src/frame_state.rs b/crates/egui/src/frame_state.rs index 0761d6506b8..184ab0d64a8 100644 --- a/crates/egui/src/frame_state.rs +++ b/crates/egui/src/frame_state.rs @@ -8,22 +8,12 @@ pub struct TooltipFrameState { /// If a tooltip has been shown this frame, where was it? /// This is used to prevent multiple tooltips to cover each other. pub widget_tooltips: IdMap, - - /// For each layer, which widget is showing a tooltip (if any)? - /// - /// Only one widget per layer may show a tooltip. - /// But if a tooltip contains a tooltip, you can show a tooltip on top of a tooltip. - pub per_layer_tooltip_widget: ahash::HashMap, } impl TooltipFrameState { pub fn clear(&mut self) { - let Self { - widget_tooltips, - per_layer_tooltip_widget, - } = self; + let Self { widget_tooltips } = self; widget_tooltips.clear(); - per_layer_tooltip_widget.clear(); } } @@ -42,6 +32,12 @@ pub struct PerLayerState { /// /// Does NOT include tooltips. pub open_popups: HashSet, + + /// Which widget is showing a tooltip (if any)? + /// + /// Only one widget per layer may show a tooltip. + /// But if a tooltip contains a tooltip, you can show a tooltip on top of a tooltip. + pub widget_with_tooltip: Option, } #[cfg(feature = "accesskit")] diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index a64ed0ddafa..9da42e56b47 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -656,10 +656,12 @@ impl Response { } let is_other_tooltip_open = self.ctx.prev_frame_state(|fs| { - if let Some(already_open_tooltip) = - fs.tooltips.per_layer_tooltip_widget.get(&self.layer_id) + if let Some(already_open_tooltip) = fs + .layers + .get(&self.layer_id) + .and_then(|layer| layer.widget_with_tooltip) { - already_open_tooltip != &self.id + already_open_tooltip != self.id } else { false }