Skip to content

Commit

Permalink
Close context menus with Escape (emilk#4711)
Browse files Browse the repository at this point in the history
Pressing escape should close any menu or popup
  • Loading branch information
emilk authored and hacknus committed Oct 30, 2024
1 parent 557ad36 commit a5d59fb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl MenuRootManager {
) -> Option<InnerResponse<R>> {
if let Some(root) = self.inner.as_mut() {
let (menu_response, inner_response) = root.show(button, add_contents);
if MenuResponse::Close == menu_response {
if menu_response.is_close() {
self.inner = None;
}
inner_response
Expand Down Expand Up @@ -323,7 +323,8 @@ impl MenuRoot {
let inner_response = menu_popup(&button.ctx, &self.menu_state, self.id, add_contents);
let menu_state = self.menu_state.read();

if menu_state.response.is_close() {
let escape_pressed = button.ctx.input(|i| i.key_pressed(Key::Escape));
if menu_state.response.is_close() || escape_pressed {
return (MenuResponse::Close, Some(inner_response));
}
}
Expand Down

0 comments on commit a5d59fb

Please sign in to comment.