diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index 74a5586b04..f22c57ce6e 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -319,10 +319,14 @@ pub(crate) fn floating_window<'a>(layout: &'a Layout, panel: &str) -> Op /// The top left a new floating window `height` tall takes beside the window floated last: a cascade /// step from it, inside the float space. None while nothing floats. pub(crate) fn cascaded_float_origin(app: &VectorcraftApp, height: f32) -> Option { - let last = layout_of(&app.ui).floating.last()?.rect; let space = command_space(app); let size = egui::vec2(space.default_size.x, height); - Some(craft::behavior::placement::cascade(last, size, space.area, space.inset).min) + cascaded_float_rect(layout_of(&app.ui), &space, size).map(|rect| rect.min) +} + +fn cascaded_float_rect(layout: &Layout, space: &FloatSpace, size: egui::Vec2) -> Option { + let last = layout.floating.last()?.rect; + Some(craft::behavior::placement::cascade(last, size, space.area, space.inset)) } /// Is `panel` showing: in front of its group and not in a column collapsed to icons, or in the @@ -958,7 +962,8 @@ fn show_actions(ws: &Workspace, space: &FloatSpace, panel: &str, (Some(mate), _) => vec![Action::open_at(id, (*mate).to_owned(), DockPlacement::tab(None))], (None, true) => vec![Action::open(id, first_dock_panel(layout, panel))], (None, false) => { - let rect = space.place(space.size_of(&DragUnit::Panel(id.clone()), None)); + let size = space.size_of(&DragUnit::Panel(id.clone()), None); + let rect = cascaded_float_rect(layout, space, size).unwrap_or_else(|| space.place(size)); vec![Action::float(id, rect)] } } diff --git a/crates/ui-egui/src/panel_docking/tests.rs b/crates/ui-egui/src/panel_docking/tests.rs index 3476f5c2b0..3ae34b7ae5 100644 --- a/crates/ui-egui/src/panel_docking/tests.rs +++ b/crates/ui-egui/src/panel_docking/tests.rs @@ -784,6 +784,24 @@ fn independently_reopened_tab_is_not_restored_by_the_group_key() { assert!(showing(&h.app.ui, "layers")); } +#[test] +fn new_window_panels_cascade_and_reopened_panels_keep_their_positions() { + let mut h = Harness::new(); + let show = |h: &mut Harness, panel: &str| { + h.app.run("window.panel", json!({"panel": panel, "toggle": true})).unwrap(); + floating_window(&h.layout(), panel).unwrap().rect + }; + let trace = show(&mut h, "imageTrace"); + let preview = show(&mut h, "separations"); + assert_ne!(trace.min, preview.min, "the second panel must leave the first title bar visible"); + + h.app.run("window.panel.float", json!({"panel": "imageTrace", "x": 180, "y": 100})).unwrap(); + let moved = floating_window(&h.layout(), "imageTrace").unwrap().rect; + assert_ne!(moved.min, trace.min); + h.app.run("window.panel.close", json!({"panel": "imageTrace"})).unwrap(); + assert_eq!(show(&mut h, "imageTrace"), moved, "reopening a placed panel restores its chosen position"); +} + #[test] fn showing_a_hidden_floating_group_returns_its_window_panels() { let mut h = Harness::new();