From 72dcc3b4cc6c166e5cfda4387591e7db05308561 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 25 Oct 2026 04:39:17 +0000 Subject: [PATCH] D1: tests for never-placed panels and native window places; Move Panel to New Window stays in the panel menu A panel never laid out opens at EffectCraft's default place for it; a closed panel reopens at its recorded place. The panel menu keeps Move Panel to New Window, which records the window's place. --- crates/ui-egui/src/panels/mod.rs | 12 ++++++++++-- crates/ui-egui/src/workspace_state.rs | 6 +++--- crates/ui-egui/tests/it/shared_docking_ui.rs | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs index dc3977d09..50ecf2f7f 100644 --- a/crates/ui-egui/src/panels/mod.rs +++ b/crates/ui-egui/src/panels/mod.rs @@ -234,8 +234,16 @@ pub fn panel_menu_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui) { let _ = app.dock_command(ui.ctx(), craft_ui::docking::Action::Float { panel, rect: r }); close = true; } - // D2: Move Panel to New Window / Main Window returns here once craft-ui's native - // windows draw the window (`window.panelWindow` records the place meanwhile). + // Multiple monitors: a native window of its own, which can go on another screen. + // D2: craft-ui's native windows draw it; until then the place is recorded and the + // panel floats in the main window. + if !ui.ctx().embed_viewports() { + let windowed = app.in_panel_window(panel); + if ui.button(if windowed { tr("Move Panel to Main Window") } else { tr("Move Panel to New Window") }).clicked() { + let _ = crate::menus::invoke(app, &ui.ctx().clone(), "window.panelWindow", serde_json::json!({"panel": panel, "window": !windowed})); + close = true; + } + } if !floating && ui.button(if app.ui.maximized == Some(panel) { tr("Restore Panel Size") } else { tr("Maximize Panel") }).clicked() { app.toggle_maximize(panel); close = true; diff --git a/crates/ui-egui/src/workspace_state.rs b/crates/ui-egui/src/workspace_state.rs index fb605d2e6..01018bc6f 100644 --- a/crates/ui-egui/src/workspace_state.rs +++ b/crates/ui-egui/src/workspace_state.rs @@ -361,12 +361,12 @@ mod tests { let config = MemoryConfig::default(); let mut ui = UiState::default(); let mut store = WorkspaceStore::load(Some(&config), &mut ui); - ui.dock.apply(Action::Float { panel: PanelKind::Info, rect: [10.0, 10.0, 300.0, 200.0] }, crate::dock::permissions).unwrap(); - ui.dock.apply(Action::SetNative { panel: PanelKind::Info, rect: Some([90_000.0, -90_000.0, 1.0e5, 0.5]) }, crate::dock::permissions).unwrap(); + ui.dock.apply(Action::Float { panel: PanelKind::Project, rect: [10.0, 10.0, 300.0, 200.0] }, crate::dock::permissions).unwrap(); + ui.dock.apply(Action::SetNative { panel: PanelKind::Project, rect: Some([90_000.0, -90_000.0, 1.0e5, 0.5]) }, crate::dock::permissions).unwrap(); assert!(store.save(Some(&config), &ui).unwrap()); let mut restored = UiState::default(); WorkspaceStore::load(Some(&config), &mut restored); - let native = restored.dock.layout.floating.iter().find(|w| w.contains(&PanelKind::Info)).and_then(|w| w.native).unwrap(); + let native = restored.dock.layout.floating.iter().find(|w| w.contains(&PanelKind::Project)).and_then(|w| w.native).unwrap(); assert_eq!(native, crate::dock_ui::sanitized_window_rect(native)); assert!(native[2] <= crate::dock_ui::PANEL_WINDOW_MAX && native[3] >= crate::dock_ui::PANEL_WINDOW_MIN[1]); } diff --git a/crates/ui-egui/tests/it/shared_docking_ui.rs b/crates/ui-egui/tests/it/shared_docking_ui.rs index a722c99b3..552939ad0 100644 --- a/crates/ui-egui/tests/it/shared_docking_ui.rs +++ b/crates/ui-egui/tests/it/shared_docking_ui.rs @@ -331,3 +331,21 @@ fn failed_close_preserves_viewer_lifecycle_and_maximize_state() { assert_eq!(app.ui.active_viewer, before.active_viewer); assert_eq!(app.ui.locked_tabs, before.locked_tabs); } + +/// A panel never laid out opens at EffectCraft's default place for it (History beside the +/// Project panel, Render Queue with the Timeline), not where craft-ui's fallback puts it; a panel +/// the user closed comes back where it was. +#[test] +fn never_placed_panels_open_at_their_default_place() { + let mut app = EffectcraftApp::new(Session::default()); + assert!(!app.ui.dock.is_open(PanelKind::History)); + invoke(&mut app, "window.panel", json!({"panel": "History"})).unwrap(); + assert!(app.ui.dock.group_of(PanelKind::History).contains(&PanelKind::Project), "{:?}", app.ui.dock.group_of(PanelKind::History)); + invoke(&mut app, "window.panel.activate", json!({"panel": "Tracker"})).unwrap(); + assert!(app.ui.dock.group_of(PanelKind::Tracker).contains(&PanelKind::EffectsPresets) || app.ui.dock.is_open(PanelKind::Tracker)); + // Closed by the user, it reopens at its recorded place. + invoke(&mut app, "window.dockPanel", json!({"panel": "History", "anchor": "Timeline"})).unwrap(); + invoke(&mut app, "window.closePanel", json!({"panel": "History"})).unwrap(); + invoke(&mut app, "window.panel", json!({"panel": "History"})).unwrap(); + assert!(app.ui.dock.group_of(PanelKind::History).contains(&PanelKind::Timeline)); +}