From d3c1ac37989671131817dcc1a41d1731f0f7714d Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Tue, 18 Mar 2025 11:32:18 +0100 Subject: [PATCH] Fix `context_menu` not closing when clicking widget (#5799) The rerun timeline context menu wouldn't close when clicking outside, this fixes it --- crates/egui/src/containers/popup.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index a2b668ff..4d866cfd 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -273,11 +273,15 @@ impl<'a> Popup<'a> { /// In contrast to [`Self::menu`], this will open at the pointer position. pub fn context_menu(response: &Response) -> Self { Self::menu(response) - .open_memory( - response - .secondary_clicked() - .then_some(SetOpenCommand::Bool(true)), - ) + .open_memory(if response.secondary_clicked() { + Some(SetOpenCommand::Bool(true)) + } else if response.clicked() { + // Explicitly close the menu if the widget was clicked + // Without this, the context menu would stay open if the user clicks the widget + Some(SetOpenCommand::Bool(false)) + } else { + None + }) .at_pointer_fixed() }