PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Workspaces: preserve the embedding host menu and rail flags (#2620)
Arthur Wagner46af2e6e303e
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rsindex 5a46409ed..2f9d32ce7 100644--- a/crates/ui-egui/src/dock.rs+++ b/crates/ui-egui/src/dock.rs@@ -656,7 +656,10 @@ pub fn restore(app: &mut PhotocraftApp) {/// (a workspace or `panelLayout`). Missing or invalid dock parts are left alone; old/// layouts without Timeline visibility restore it closed.pub fn apply(app: &mut PhotocraftApp, v: &Value) {- if let Some(p) = v.get("panels").and_then(|p| serde_json::from_value(p.clone()).ok()) {+ if let Some(mut p) = v.get("panels").and_then(|p| serde_json::from_value::<Panels>(p.clone()).ok()) {+ // The embedding host owns these flags, including for layouts that serialize them.+ p.menu_bar = app.ui.panels.menu_bar;+ p.rail = app.ui.panels.rail;app.ui.panels = p;}if let Some(t) = v.get("dockTabs").and_then(|t| serde_json::from_value(t.clone()).ok()) {diff --git a/crates/ui-egui/src/workspace_ui.rs b/crates/ui-egui/src/workspace_ui.rsindex 583489963..3eba2798b 100644--- a/crates/ui-egui/src/workspace_ui.rs+++ b/crates/ui-egui/src/workspace_ui.rs@@ -490,6 +490,83 @@ mod tests {(PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()), egui::Context::default())}+ #[test]+ fn saved_workspaces_preserve_host_chrome_on_select_and_reset() {+ for (menu_bar, rail) in [(false, false), (false, true), (true, false), (true, true)] {+ for legacy_flags in [false, true] {+ let (mut app, ctx) = app();+ app.ui.panels.history = true;+ app.ui.panels.navigator = true;+ app.ui.timeline.open = true;+ crate::menus::invoke(&mut app, &ctx, "window.workspace.newWorkspace", json!({"name": "Host layout"})).unwrap();+ let saved = app.session.prefs().workspaces["Host layout"].clone();+ assert!(saved["panels"].get("menu_bar").is_none() && saved["panels"].get("rail").is_none());+ if legacy_flags {+ app.session.prefs.edit(|p| {+ let panels = &mut p.workspaces.get_mut("Host layout").unwrap()["panels"];+ panels["menu_bar"] = json!(!menu_bar);+ panels["rail"] = json!(!rail);+ });+ }+ app.ui.panels.menu_bar = menu_bar;+ app.ui.panels.rail = rail;+ crate::menus::invoke(&mut app, &ctx, "window.workspace.painting", json!({})).unwrap();+ crate::menus::invoke(&mut app, &ctx, "window.workspace.select", json!({"name": "Host layout"})).unwrap();+ assert_eq!((app.ui.panels.menu_bar, app.ui.panels.rail), (menu_bar, rail), "select: legacy_flags={legacy_flags}");+ let restored = json!({"dock": app.ui.dock, "dockTabs": app.ui.dock_tabs, "timelineOpen": app.ui.timeline.open});+ for key in ["dock", "dockTabs", "timelineOpen"] {+ assert_eq!(restored[key], saved[key], "select restores {key}");+ }+ assert!(app.ui.panels.history && app.ui.panels.navigator);+ app.ui.panels.menu_bar = !menu_bar;+ app.ui.panels.rail = !rail;+ app.ui.panels.history = false;+ app.ui.panels.navigator = false;+ app.ui.timeline.open = false;+ crate::menus::invoke(&mut app, &ctx, "window.workspace.resetWorkspace", json!({})).unwrap();+ assert_eq!((app.ui.panels.menu_bar, app.ui.panels.rail), (!menu_bar, !rail), "reset: legacy_flags={legacy_flags}");+ let restored = json!({"dock": app.ui.dock, "dockTabs": app.ui.dock_tabs, "timelineOpen": app.ui.timeline.open});+ for key in ["dock", "dockTabs", "timelineOpen"] {+ assert_eq!(restored[key], saved[key], "reset restores {key}");+ }+ assert!(app.ui.panels.history && app.ui.panels.navigator);+ }+ }+ }++ #[test]+ fn saved_workspace_keeps_host_menu_and_rail_hidden_in_the_rendered_ui() {+ let mut failures = Vec::new();+ for theme in crate::theme::ThemeKind::ALL {+ for width in [800.0, 1200.0] {+ let builder = egui_kittest::Harness::builder().with_size(egui::vec2(width, 800.0)).with_max_steps(64);+ let mut h = builder.build_eframe(move |cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, theme);+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("prefs.set", json!({"path": "interface.theme", "value": theme.id()})).unwrap();+ app.ui.theme = theme;+ app.ui.panels.menu_bar = false;+ app.ui.panels.rail = false;+ app+ });+ let ctx = h.ctx.clone();+ crate::menus::invoke(h.state_mut(), &ctx, "window.workspace.newWorkspace", json!({"name": "Embedded"})).unwrap();+ crate::menus::invoke(h.state_mut(), &ctx, "window.workspace.select", json!({"name": "Embedded"})).unwrap();+ h.run_steps(4);+ assert_eq!(h.state().ui.theme, theme, "the fixture renders the requested theme");+ for name in ["title_bar", "rail"] {+ if egui::containers::panel::PanelState::load(&h.ctx, egui::Id::new(name)).is_some() {+ failures.push(format!("{theme:?}, width={width}: {name} is drawn"));+ }+ }+ if h.state().ui.panels.menu_bar || h.state().ui.panels.rail {+ failures.push(format!("{theme:?}, width={width}: host flags were overwritten"));+ }+ }+ }+ assert!(failures.is_empty(), "saved workspaces expose host chrome: {failures:?}");+ }+#[test]fn new_select_delete_workspaces() {let (mut app, ctx) = app();diff --git a/docs/ui-design.md b/docs/ui-design.mdindex f4a8ac19a..393b9ec4a 100644--- a/docs/ui-design.md+++ b/docs/ui-design.md@@ -82,6 +82,11 @@ The app's top bar (`panels::title_bar`) starts with the brand mark (the app icon## Menus+An embedding application's `panels.menu_bar` and `panels.rail` flags belong to its current+session. Restoring a saved workspace or remembered panel layout preserves both flags, including+when the serialized layout contains their values. Panel visibility, dock layout, tabs and Timeline+visibility follow the saved layout.+The Pro status bar's Document Dimensions readout follows Preferences › Units & Rulers › Rulers,including changes made from a ruler's context menu. It uses the document resolution for physicalunits, each side's own extent for percentages and the selected point-size convention for points