diff --git a/crates/ui-egui/src/chrome_settle_trials.rs b/crates/ui-egui/src/chrome_settle_trials.rs index 50ac07d5a3f..d799c2d56ec 100644 --- a/crates/ui-egui/src/chrome_settle_trials.rs +++ b/crates/ui-egui/src/chrome_settle_trials.rs @@ -1,22 +1,21 @@ //! The window's chrome settles (#15493): a frame whose only input is the pointer moving over the canvas runs no dock //! group header, panel tab strip or grip and no title bar; each repaints its last run. Before, every frame ran them. +//! What the chrome shows runs it again: the UI language, the toolbar's slots, the title and whether the menu bar +//! takes the menu keys. use craft::ui::runtime::measure::last_pass_runs; -use egui::{Event, vec2}; +use egui::accesskit::Role; +use egui::{Event, Key, Modifiers, vec2}; use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; use serde_json::json; use crate::PhotocraftApp; -/// The chrome components the last pass ran, by type name. -fn chrome_runs(h: &Harness<'static, Box>) -> Vec<(&'static str, u32)> { - const CHROME: [&str; 4] = - ["docking::group::DockGroup<", "docking::group::GroupGrip<", "TabStrip<'_, craft_ui_panels::docking::PanelKey>", "title_bar::bar::TitleBar<"]; - last_pass_runs(&h.ctx).into_iter().filter(|(ty, _)| CHROME.iter().any(|name| ty.contains(name))).collect() -} +type H = Harness<'static, Box>; -#[test] -fn a_hover_over_the_canvas_runs_no_dock_chrome_and_no_title_bar() { +/// The whole app on a new document, with the pointer resting over the canvas. +fn harness() -> H { let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).with_step_dt(1.0 / 60.0).build_eframe(|cc| { PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); let mut session = photocraft_engine::Session::new(); @@ -27,6 +26,25 @@ fn a_hover_over_the_canvas_runs_no_dock_chrome_and_no_title_bar() { let at = h.state().last_canvas_rect.center(); h.event(Event::PointerMoved(at)); h.run_steps(4); + h +} + +/// The chrome components the last pass ran, by type name. +fn chrome_runs(h: &H) -> Vec<(&'static str, u32)> { + const CHROME: [&str; 4] = + ["docking::group::DockGroup<", "docking::group::GroupGrip<", "TabStrip<'_, craft_ui_panels::docking::PanelKey>", "title_bar::bar::TitleBar<"]; + last_pass_runs(&h.ctx).into_iter().filter(|(ty, _)| CHROME.iter().any(|name| ty.contains(name))).collect() +} + +/// Whether the chrome component named `name` ran in the last pass. +fn ran(h: &H, name: &str) -> bool { + chrome_runs(h).iter().any(|(ty, _)| ty.contains(name)) +} + +#[test] +fn a_hover_over_the_canvas_runs_no_dock_chrome_and_no_title_bar() { + let mut h = harness(); + let at = h.state().last_canvas_rect.center(); assert!(!last_pass_runs(&h.ctx).is_empty(), "the frame runs components"); for step in 1..=3 { h.event(Event::PointerMoved(at + vec2(step as f32, 0.0))); @@ -34,3 +52,56 @@ fn a_hover_over_the_canvas_runs_no_dock_chrome_and_no_title_bar() { assert_eq!(chrome_runs(&h), [], "hover step {step}: the dock chrome and the title bar repaint their last run"); } } + +/// With no input reaching it, the chrome runs in the frame after what it shows changes: a new UI language (panel names +/// and menu titles), a toolbar slot hidden (the toolbar column's grid) and an edit that marks the document unsaved +/// (the title). A version that missed one would replay the old chrome. +#[test] +fn the_chrome_runs_when_what_it_shows_changes() { + let mut h = harness(); + assert_eq!(chrome_runs(&h), [], "settled"); + + h.state_mut().session.prefs.edit(|prefs| prefs.interface.language = "fr".into()); + h.run_steps(1); + assert!(ran(&h, "TabStrip<") && ran(&h, "TitleBar<"), "a new language runs the tab strips and the title bar: {:?}", chrome_runs(&h)); + h.run_steps(2); + + h.state_mut().session.prefs.edit(|prefs| prefs.toolbar.hidden.push("Brush".to_string())); + h.run_steps(1); + assert!(ran(&h, "DockGroup<"), "a hidden toolbar slot runs the dock groups: {:?}", chrome_runs(&h)); + h.run_steps(2); + + assert!(!h.state().session.active().unwrap().is_dirty(), "the new document is saved"); + h.state_mut().run("layer.new.layer", json!({})).unwrap(); + h.run_steps(1); + assert!(ran(&h, "TitleBar<"), "an unsaved edit runs the title bar: {:?}", chrome_runs(&h)); +} + +/// A dialog closed with Escape runs no command, and the menu bar takes the menu keys again: Alt+F opens the File menu. +#[test] +fn the_menu_keys_open_a_menu_after_a_dialog_closes_with_escape() { + let mut h = harness(); + let items = |h: &H| h.query_all_by_role(Role::MenuItem).count(); + let titles = items(&h); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "image.imageSize", json!({})).unwrap(); + h.run_steps(4); + assert!(h.state().dialog_open(), "Image Size is open"); + h.key_press(Key::Escape); + h.run_steps(4); + assert!(!h.state().dialog_open(), "Escape closed it"); + h.key_press_modifiers(Modifiers::ALT, Key::F); + h.run_steps(4); + assert!(items(&h) > titles, "Alt+F opens the File menu: {} menu items, {titles} titles", items(&h)); +} + +/// The caption buttons follow the window state: a window maximized at the size it had shows Restore. +#[test] +fn a_maximized_window_shows_restore() { + let mut h = harness(); + let label = |h: &H, name: &str| h.query_all_by_label(name).count(); + assert!(label(&h, "Maximize") > 0, "a normal window shows Maximize"); + h.input_mut().viewports.entry(egui::ViewportId::ROOT).or_default().maximized = Some(true); + h.run_steps(3); + assert!(label(&h, "Restore") > 0 && label(&h, "Maximize") == 0, "a maximized window shows Restore"); +} diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index 6c1a473f30e..dd2ec99545b 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -16,10 +16,14 @@ pub(crate) fn options_bar(app: &PhotocraftApp) -> u64 { } /// The version of the title bar: the title it shows (the active document's name and its unsaved mark), the language -/// its menu titles are in and whether the menus are in the bar (not in the macOS menu bar). An open menu is an overlay -/// and runs as it is shown. +/// its menu titles are in, whether the menus are in the bar (not in the macOS menu bar) and whether the bar takes the +/// menu keys (F10, Alt, Alt+letter), which a dialog or the shortcut recorder holds back: a dialog closed with Escape +/// runs no command, and the bar registers for the keys again only when it runs. An open menu is an overlay and runs as +/// it is shown. pub(crate) fn title_bar(app: &PhotocraftApp) -> u64 { - version(app, (super::title_bar::title_text(app), crate::i18n::current().code(), app.services.native_menu.is_none())) + let (gate, _) = crate::menus::menu_gate(app); + let keys = (gate.modal, gate.recording_shortcut); + version(app, (super::title_bar::title_text(app), crate::i18n::current().code(), app.services.native_menu.is_none(), keys)) } /// The version of what the dock's chrome (each group's header and tab strip, each column's bar) shows of the panels