diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index db5a9e3e8bd..b4c7bbca7d3 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -270,6 +270,16 @@ impl ComboBox { } response } + + /// Check if the [`ComboBox`] with the given id has its popup menu currently opened. + pub fn is_open(ctx: &Context, id: Id) -> bool { + ctx.memory(|m| m.is_popup_open(Self::widget_to_popup_id(id))) + } + + /// Convert a [`ComboBox`] id to the id used to store it's popup state. + fn widget_to_popup_id(widget_id: Id) -> Id { + widget_id.with("popup") + } } #[allow(clippy::too_many_arguments)] @@ -282,7 +292,7 @@ fn combo_box_dyn<'c, R>( wrap_mode: Option, (width, height): (Option, Option), ) -> InnerResponse> { - let popup_id = button_id.with("popup"); + let popup_id = ComboBox::widget_to_popup_id(button_id); let is_popup_open = ui.memory(|m| m.is_popup_open(popup_id)); diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index d980bd78eb6..264d53d5983 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -2,7 +2,8 @@ use std::{any::Any, sync::Arc}; use crate::{ emath::{Align, Pos2, Rect, Vec2}, - menu, Context, CursorIcon, Id, LayerId, PointerButton, Sense, Ui, WidgetRect, WidgetText, + menu, ComboBox, Context, CursorIcon, Id, LayerId, PointerButton, Sense, Ui, WidgetRect, + WidgetText, }; // ---------------------------------------------------------------------------- @@ -571,6 +572,10 @@ impl Response { return false; } + if ComboBox::is_open(&self.ctx, self.id) { + return false; // Don't cover the open ComboBox with a tooltip + } + if self.enabled { if !self.hovered || !self.ctx.input(|i| i.pointer.has_pointer()) { return false;