Menus: arrow keys and Enter drive the menu bar; shortcuts wait while a menu is open (#279)
The in-window menu bar now works from the keyboard as After Effects' does on Windows: Alt pressed and released on its own focuses the bar, Left / Right move between its menus and Down, Enter or Space opens one. In an open menu Up / Down move the highlight (skipping disabled entries, wrapping around), Right opens the highlighted submenu and Left closes it (on a plain entry they open the next / previous menu), Enter or Space chooses the entry and Escape closes the menus. Hovering an entry moves the highlight there, and a highlighted entry scrolls into view in long menus. While a menu, context menu or popup list is open, or the bar has the keyboard, keys go to the menus only: the app's shortcuts don't run (Space started the preview behind an open menu) and the panels don't see the keys (Enter on an entry no longer reaches the Project panel's rename). Tall menus already scroll inside the window since #277 (ui_scrolling's a_menu_taller_than_the_window_scrolls). F10 stays View > Switch 3D View > Front, as in After Effects. Test: ui_menus (shortcuts_wait_while_a_menu_is_open, arrow_keys_drive_the_menu_bar, enter_chooses_the_highlighted_entry). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4aaadd0ed3
commit
6bb9bd8dab
@@ -459,6 +459,8 @@ pub fn popup_list<R>(ui: &mut Ui, id: egui::Id, pos: egui::Pos2, anchor: Rect, r
|
||||
egui::ScrollArea::vertical().max_height(max_h).min_scrolled_height((est - 16.0).min(max_h)).show(ui, |ui| chosen = body(ui));
|
||||
});
|
||||
});
|
||||
let pass = ui.ctx().cumulative_pass_nr();
|
||||
ui.ctx().data_mut(|d| d.insert_temp(popup_list_pass_id(), pass));
|
||||
let outside = pressed_outside(ui.ctx(), &area.response) && !ui.input(|i| i.pointer.interact_pos()).is_some_and(|p| anchor.contains(p));
|
||||
if chosen.is_some() || outside || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
ui.data_mut(|d| d.insert_temp(id.with("open"), false));
|
||||
@@ -466,6 +468,18 @@ pub fn popup_list<R>(ui: &mut Ui, id: egui::Id, pos: egui::Pos2, anchor: Rect, r
|
||||
chosen
|
||||
}
|
||||
|
||||
/// The pass a [`popup_list`] was last drawn in.
|
||||
fn popup_list_pass_id() -> egui::Id {
|
||||
egui::Id::new("popup-list-pass")
|
||||
}
|
||||
|
||||
/// Whether a menu, context menu or popup list is open, or the menu bar has the keyboard (as of
|
||||
/// the last frame): the app's keyboard shortcuts wait until it closes (#279).
|
||||
pub fn any_menu_open(ctx: &egui::Context) -> bool {
|
||||
let list_pass: Option<u64> = ctx.data(|d| d.get_temp(popup_list_pass_id()));
|
||||
egui::Popup::is_any_open(ctx) || crate::menu_keys::active(ctx) || list_pass.is_some_and(|p| p + 1 >= ctx.cumulative_pass_nr())
|
||||
}
|
||||
|
||||
/// A menu's (or submenu's) entries, scrolling with a scroll bar when they are taller than the
|
||||
/// window instead of running off it (Edit on a short screen, #269; Blending Mode). Others show
|
||||
/// whole: egui sizes a new menu from a default 400 pt area, so without a minimum a longer one
|
||||
|
||||
Reference in New Issue
Block a user