Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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,
}
Expand Down Expand Up @@ -519,7 +519,7 @@ impl<'a> Popup<'a> {
_ => mem.open_popup(id),
}
} else {
mem.close_popup();
mem.close_popup(id);
}
}
Some(SetOpenCommand::Toggle) => {
Expand Down Expand Up @@ -599,7 +599,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));
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions crates/egui/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down