diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 4d866cfd..7c72d2dd 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -85,7 +85,7 @@ pub enum PopupCloseBehavior { /// but in the popup's body CloseOnClickOutside, - /// Clicks will be ignored. Popup might be closed manually by calling [`crate::Memory::close_popup`] + /// Clicks will be ignored. Popup might be closed manually by calling [`crate::Memory::close_all_popups`] /// or by pressing the escape button IgnoreClicks, } @@ -524,7 +524,7 @@ impl<'a> Popup<'a> { _ => mem.open_popup(id), } } else { - mem.close_popup(); + mem.close_popup(id); } } Some(SetOpenCommand::Toggle) => { @@ -606,7 +606,7 @@ impl<'a> Popup<'a> { } OpenKind::Memory { .. } => { if should_close { - ctx.memory_mut(|mem| mem.close_popup()); + ctx.memory_mut(|mem| mem.close_popup(id)); } } } diff --git a/crates/egui/src/memory/mod.rs b/crates/egui/src/memory/mod.rs index d38e39f7..c68ba4da 100644 --- a/crates/egui/src/memory/mod.rs +++ b/crates/egui/src/memory/mod.rs @@ -1098,17 +1098,26 @@ impl Memory { .and_then(|(popup_id, pos)| if popup_id == id { pos } else { None }) } - /// Close the open popup, if any. - pub fn close_popup(&mut self) { + /// Close any currently open popup. + pub fn close_all_popups(&mut self) { self.popup = None; } + /// Close the given popup, if it is open. + /// + /// See also [`Self::close_all_popups`] if you want to close any / all currently open popups. + pub fn close_popup(&mut self, popup_id: Id) { + if self.is_popup_open(popup_id) { + self.popup = None; + } + } + /// Toggle the given popup between closed and open. /// /// Note: At most, only one popup can be open at a time. pub fn toggle_popup(&mut self, popup_id: Id) { if self.is_popup_open(popup_id) { - self.close_popup(); + self.close_popup(popup_id); } else { self.open_popup(popup_id); } diff --git a/crates/egui/src/widgets/color_picker.rs b/crates/egui/src/widgets/color_picker.rs index a9906cef..500fb0b8 100644 --- a/crates/egui/src/widgets/color_picker.rs +++ b/crates/egui/src/widgets/color_picker.rs @@ -521,7 +521,7 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Res if !button_response.clicked() && (ui.input(|i| i.key_pressed(Key::Escape)) || area_response.clicked_elsewhere()) { - ui.memory_mut(|mem| mem.close_popup()); + ui.memory_mut(|mem| mem.close_popup(popup_id)); } }