Close context menus with Escape (#4711)
Pressing escape should close any menu or popup
This commit is contained in:
parent
1036e18440
commit
fd85557463
|
|
@ -271,7 +271,7 @@ impl MenuRootManager {
|
||||||
) -> Option<InnerResponse<R>> {
|
) -> Option<InnerResponse<R>> {
|
||||||
if let Some(root) = self.inner.as_mut() {
|
if let Some(root) = self.inner.as_mut() {
|
||||||
let (menu_response, inner_response) = root.show(button, add_contents);
|
let (menu_response, inner_response) = root.show(button, add_contents);
|
||||||
if MenuResponse::Close == menu_response {
|
if menu_response.is_close() {
|
||||||
self.inner = None;
|
self.inner = None;
|
||||||
}
|
}
|
||||||
inner_response
|
inner_response
|
||||||
|
|
@ -323,7 +323,8 @@ impl MenuRoot {
|
||||||
let inner_response = menu_popup(&button.ctx, &self.menu_state, self.id, add_contents);
|
let inner_response = menu_popup(&button.ctx, &self.menu_state, self.id, add_contents);
|
||||||
let menu_state = self.menu_state.read();
|
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));
|
return (MenuResponse::Close, Some(inner_response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue