From f6671c50010ec1ff976258708848a6fd36298582 Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:42:24 +0900 Subject: [PATCH 1/2] fix(shortcuts): give the tabs the full dialog width --- crates/menu/src/shortcuts/view.rs | 2 +- crates/menu/tests/it/shortcuts/mod.rs | 1 + crates/menu/tests/it/shortcuts/tabs.rs | 88 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 crates/menu/tests/it/shortcuts/tabs.rs diff --git a/crates/menu/src/shortcuts/view.rs b/crates/menu/src/shortcuts/view.rs index cbb4858d7..f4846e432 100644 --- a/crates/menu/src/shortcuts/view.rs +++ b/crates/menu/src/shortcuts/view.rs @@ -130,7 +130,7 @@ fn app_tabs(ui: &mut Ui, env: &mut Env<'_>, state: &mut DialogState) -> Option { state.set_tab(i.checked_sub(1).and_then(|k| ids.get(k).copied())); diff --git a/crates/menu/tests/it/shortcuts/mod.rs b/crates/menu/tests/it/shortcuts/mod.rs index b7d702d49..ad05aa068 100644 --- a/crates/menu/tests/it/shortcuts/mod.rs +++ b/crates/menu/tests/it/shortcuts/mod.rs @@ -4,3 +4,4 @@ mod import_offer; mod recorder; mod rows; mod sets; +mod tabs; diff --git a/crates/menu/tests/it/shortcuts/tabs.rs b/crates/menu/tests/it/shortcuts/tabs.rs new file mode 100644 index 000000000..3d52ab4f7 --- /dev/null +++ b/crates/menu/tests/it/shortcuts/tabs.rs @@ -0,0 +1,88 @@ +//! The app's pages share the Keyboard Shortcuts dialog's width and navigation. + +use craft_host::target::Os; +use craft_keymap::{Platform, Profiles}; +use craft_menu::shortcuts::{Area, DialogState, DialogTab, ShortcutsDialog}; +use craft_theme::ThemeId; +use craft_ui::contract::Role; +use craft_ui::runtime::egui::access::AccessTree; +use craft_ui::runtime::env::RootEnv; +use craft_ui::testing::{Fixture, Frames, pointer, trial}; + +use super::fixture; + +fn dialog_at_125_percent(toolbar_label: &str) -> (Frames, impl FnMut(&mut egui::Ui) + '_) { + // Use the Windows test context and a 1600 × 1000 physical-pixel window at 125%. + let mut os = Fixture::new(|_| {}); + os.os(Os::Windows); + let mut frames = Frames::over(os.ctx().clone()); + frames.screen(egui::vec2(1280.0, 800.0)); + frames.pixels_per_point(1.25); + let mut root = RootEnv::default(); + root.set_theme(ThemeId::parse("craft.artcraft").unwrap()); + frames.root(root); + + let mut keys = fixture::keymap(Platform::Windows); + let mut state = DialogState::new(); + let mut profiles = Profiles::default(); + let builtins = fixture::builtins(); + let options = fixture::options().with(|o| { + o.title = Some("Keyboard Shortcuts and Menus".into()); + o.areas = Area::photoshop(); + }); + let show = move |ui: &mut egui::Ui| { + let mut tabs = [ + DialogTab::new("menus", "Menus", |ui| { + ui.label("Menu item visibility"); + false + }), + DialogTab::new("toolbar", toolbar_label, |ui| { + ui.label("Toolbar tool visibility"); + false + }), + ]; + ShortcutsDialog::new(&mut keys).sets(&mut profiles, &builtins).options(&options).tabs(&mut tabs).show(ui, &mut state); + }; + (frames, show) +} + +fn tab_bounds(tree: &AccessTree, label: &str) -> egui::Rect { + let tab = tree.keys().into_iter().find(|&key| tree.role_of(key) == Some(Role::TAB) && tree.name_of(key) == Some(label)); + tab.and_then(|key| tree.bounds_of(key)).unwrap_or_else(|| panic!("no tab labelled {label}")) +} + +#[trial] +fn app_tabs_show_full_labels_at_125_percent_and_switch_pages() { + let (mut frames, mut show) = dialog_at_125_percent("Toolbar"); + frames.idle(12, &mut show); + assert_eq!(frames.ctx.pixels_per_point(), 1.25); + let tree = frames.tree(); + let tabs = ["Keyboard Shortcuts", "Menus", "Toolbar"].map(|label| { + let rect = tab_bounds(&tree, label); + let text = frames.texts().iter().find(|text| text.text == label).unwrap_or_else(|| panic!("no painted label {label}")); + assert!(!text.elided && text.clip.contains_rect(text.rect), "{label} is clipped: {text:?}"); + rect + }); + assert!(tabs.windows(2).all(|pair| pair[0].right() <= pair[1].left())); + + for (label, page) in [("Menus", "Menu item visibility"), ("Toolbar", "Toolbar tool visibility")] { + // A page can change the dialog's bounds, so target the tab in the current frame. + frames.idle(2, &mut show); + let tab = tab_bounds(&frames.tree(), label); + pointer::click(&mut frames, tab.center(), &mut show); + assert!(frames.texts().iter().any(|text| text.text == page), "click should show {page}"); + } +} + +#[trial] +fn app_tabs_keep_overflow_when_the_labels_do_not_fit() { + let long_label = "Toolbar ".repeat(200); + let (mut frames, mut show) = dialog_at_125_percent(&long_label); + frames.idle(12, &mut show); + let tree = frames.tree(); + let overflow = tree.keys().into_iter().find(|&key| tree.role_of(key) == Some(Role::BUTTON) && tree.name_of(key) == Some("More tabs")); + let overflow = overflow.and_then(|key| tree.bounds_of(key)).expect("oversized titles still have an overflow menu"); + pointer::click(&mut frames, overflow.center(), &mut show); + let popup = frames.tree(); + assert!(popup.keys().into_iter().any(|key| popup.name_of(key) == Some(long_label.as_str())), "the hidden toolbar remains available"); +} From d0c7789b295883df152096c721495748b6f33a4d Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:55:18 +0900 Subject: [PATCH 2/2] fix(shortcuts): activate tabs picked from the overflow menu --- crates/menu/src/shortcuts/view.rs | 8 +++++--- crates/menu/tests/it/shortcuts/tabs.rs | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/menu/src/shortcuts/view.rs b/crates/menu/src/shortcuts/view.rs index f4846e432..faff5b9ec 100644 --- a/crates/menu/src/shortcuts/view.rs +++ b/crates/menu/src/shortcuts/view.rs @@ -111,9 +111,11 @@ pub(super) fn tab_strip(ui: &mut Ui, name: &'static str, titles: &[String], show .kind(TabKind::Text) .shown(shown) .show_items(ui, &Titles(titles), &mut |key, _| Tab::new(titles[*key].clone()).id_salt(("tab", *key))); - strip.response.events.into_iter().find_map(|event| match event { - CollectionEvent::Selection(SelectionChange::Set(keys)) => keys.last().copied(), - _ => None, + strip.picked.or_else(|| { + strip.response.events.into_iter().find_map(|event| match event { + CollectionEvent::Selection(SelectionChange::Set(keys)) => keys.last().copied(), + _ => None, + }) }) } diff --git a/crates/menu/tests/it/shortcuts/tabs.rs b/crates/menu/tests/it/shortcuts/tabs.rs index 3d52ab4f7..51a05e2b7 100644 --- a/crates/menu/tests/it/shortcuts/tabs.rs +++ b/crates/menu/tests/it/shortcuts/tabs.rs @@ -84,5 +84,9 @@ fn app_tabs_keep_overflow_when_the_labels_do_not_fit() { let overflow = overflow.and_then(|key| tree.bounds_of(key)).expect("oversized titles still have an overflow menu"); pointer::click(&mut frames, overflow.center(), &mut show); let popup = frames.tree(); - assert!(popup.keys().into_iter().any(|key| popup.name_of(key) == Some(long_label.as_str())), "the hidden toolbar remains available"); + let hidden = popup.keys().into_iter().find(|&key| popup.name_of(key) == Some(long_label.as_str())); + let hidden = hidden.and_then(|key| popup.bounds_of(key)).expect("the hidden toolbar remains available"); + pointer::click(&mut frames, hidden.center(), &mut show); + frames.idle(2, &mut show); + assert!(frames.texts().iter().any(|text| text.text == "Toolbar tool visibility"), "the overflow choice opens the Toolbar page"); }