From a3cb54a73dcd031d8274cea5963016e57b92a3f2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 18:54:54 -0800 Subject: [PATCH] Panels: float geometry resizes only whole native windows Follow-up to #8411. `window.panel.float` with `group: true` on one entry of an accordion no longer resizes the accordion's native window; the entry floats into a window of its own, as it does when the window is drawn. A tab group given geometry before the main window reports its origin keeps its native window, and the queued geometry applies to that window instead of being dropped. The queued geometry only moves or resizes the window. Panels hidden with `window.panels` after the command stay hidden. The `window.panel.float` description and docs/mcp.md show `onto` and the geometry fields as separate forms, and say that a panel sharing a native window floats into a new window while the shared window keeps its other panels. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panel_docking.rs | 11 +++- .../ui-egui/src/panel_docking/native_tests.rs | 55 +++++++++++++++++++ docs/mcp.md | 10 +++- 5 files changed, 74 insertions(+), 6 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index c3dbf78293..67572d1e21 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -772,7 +772,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel.float", "Float Panel", "", - "{panel: id or \"tools\", x?, y?, width?, height?, group?: bool, column?: bool or n, onto?: id, above?: id, below?: id, collapsed?: bool} float a panel (with `group`, its whole group; with `column`, its whole dock column or floating window) as a floating window with its top-left corner at x, y in window points (default: inside the dock area, cascaded), as dragging its tab out does; a whole floating window keeps its rect unless given one. Supplied geometry also moves or resizes an existing native window; omitted components keep their current values. `onto` makes it a tab of the floating group holding that panel instead; `above` / `below` a group of its own above or below the group holding that panel, in its floating window or dock column. `collapsed` then minimizes (true) or restores (false) its window or group. A hidden panel shows first. \"tools\" floats the Tools panel at x, y. Returns {layout, closed, floating}", + "{panel: id or \"tools\", x?, y?, width?, height?, group?: bool, column?: bool or n, onto?: id, above?: id, below?: id, collapsed?: bool} float a panel (with `group`, its whole group; with `column`, its whole dock column or floating window) as a floating window with its top-left corner at x, y in window points (default: inside the dock area, cascaded), as dragging its tab out does; a whole floating window keeps its rect unless given one. Supplied geometry also moves or resizes an existing native window when the float takes the whole window (a panel alone in it, `column`, or `group` on a tab group that fills it); omitted components keep their current values. A panel that shares its native window floats into a new window instead, and the shared window keeps its other panels. `onto` makes it a tab of the floating group holding that panel instead; `above` / `below` a group of its own above or below the group holding that panel, in its floating window or dock column. `collapsed` then minimizes (true) or restores (false) its window or group. A hidden panel shows first. \"tools\" floats the Tools panel at x, y. Returns {layout, closed, floating}", ), ( "window.panel.dock", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index d2c72aae40..67d58232e9 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -773,7 +773,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel.float", "Float Panel", "", - "{panel: id or \"tools\", x?, y?, width?, height?, group?: bool, column?: bool or n, onto?: id, above?: id, below?: id, collapsed?: bool} float a panel (with `group`, its whole group; with `column`, its whole dock column or floating window) as a floating window with its top-left corner at x, y in window points (default: inside the dock area, cascaded), as dragging its tab out does; a whole floating window keeps its rect unless given one. Supplied geometry also moves or resizes an existing native window; omitted components keep their current values. `onto` makes it a tab of the floating group holding that panel instead; `above` / `below` a group of its own above or below the group holding that panel, in its floating window or dock column. `collapsed` then minimizes (true) or restores (false) its window or group. A hidden panel shows first. \"tools\" floats the Tools panel at x, y. Returns {layout, closed, floating}", + "{panel: id or \"tools\", x?, y?, width?, height?, group?: bool, column?: bool or n, onto?: id, above?: id, below?: id, collapsed?: bool} float a panel (with `group`, its whole group; with `column`, its whole dock column or floating window) as a floating window with its top-left corner at x, y in window points (default: inside the dock area, cascaded), as dragging its tab out does; a whole floating window keeps its rect unless given one. Supplied geometry also moves or resizes an existing native window when the float takes the whole window (a panel alone in it, `column`, or `group` on a tab group that fills it); omitted components keep their current values. A panel that shares its native window floats into a new window instead, and the shared window keeps its other panels. `onto` makes it a tab of the floating group holding that panel instead; `above` / `below` a group of its own above or below the group holding that panel, in its floating window or dock column. `collapsed` then minimizes (true) or restores (false) its window or group. A hidden panel shows first. \"tools\" floats the Tools panel at x, y. Returns {layout, closed, floating}", ), ( "window.panel.dock", diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index fb0ab20a30..f3f6c25489 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -867,7 +867,8 @@ fn native_float_geometry(app: &VectorcraftApp, command: &mut DockCommand return None; } let window = floating_window(layout, panel)?; - let whole = *column || window.panels().count() == 1 || (*group && matches!(window.root, Node::Tabs { .. } | Node::Stack { .. })); + // A group of an accordion (`Node::Stack`) is its one entry, which floats into a window of its own. + let whole = *column || window.panels().count() == 1 || (*group && matches!(window.root, Node::Tabs { .. })); if !whole { return None; } @@ -901,6 +902,11 @@ fn native_float_geometry(app: &VectorcraftApp, command: &mut DockCommand fields.insert(name.into(), json!(value)); } } + // A tab group given a rect floats as a new window without its native rect; without one it + // keeps the window, and the replay applies the geometry. + if *group && !*column { + [*x, *y, *width, *height] = [None; 4]; + } return Some(NativeFloatGeometry::Deferred { window: window.id, params }); }; // Native windows report desktop coordinates; float commands use the main window's points. @@ -1229,9 +1235,12 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) { // The original panel may have docked while other panels kept this native window. fields.insert("panel".into(), json!(panel)); fields.insert("column".into(), json!(true)); + // Only the geometry: panels hidden since the command stay hidden. + let (dock, raise) = (app.ui.dock, app.dock_rt.raise.clone()); if let Err(error) = shared_command(app, "window.panel.float", ¶ms) { app.ui.status = error; } + (app.ui.dock, app.dock_rt.raise) = (dock, raise); } } crate::tools_float::set_dock_area_left(&ctx, ui.available_rect_before_wrap().left()); diff --git a/crates/ui-egui/src/panel_docking/native_tests.rs b/crates/ui-egui/src/panel_docking/native_tests.rs index e9e8c4a3df..768ad623ff 100644 --- a/crates/ui-egui/src/panel_docking/native_tests.rs +++ b/crates/ui-egui/src/panel_docking/native_tests.rs @@ -358,6 +358,61 @@ fn saved_native_geometry_updates_before_viewport_metadata_is_available() { assert_eq!(h.host.borrow().windows[&viewport].rect.min, ORIGIN + vec2(480.0, 260.0)); } +/// Swatches and Color as tabs of one native window, with its OS window drawn. +fn native_tab_group(h: &mut Harness) -> ViewportId { + let viewport = h.float("swatches"); + h.app.run("window.panel.float", json!({"panel": "color", "onto": "swatches"})).unwrap(); + h.frames(3); + assert_eq!(h.viewport("color"), viewport); + viewport +} + +#[test] +fn a_deferred_group_float_of_one_accordion_entry_leaves_the_accordion_window_alone() { + let mut h = Harness::new(); + let viewport = native_tab_group(&mut h); + let mut layout = layout_of(&h.app.ui); + let entry = |panel: &str| craft_ui::docking::StackEntry { panel: panel.to_string(), open: true, height: None }; + layout.floating.iter_mut().find(|w| w.contains(&"swatches".to_string())).unwrap().root = + Node::Stack { entries: vec![entry("swatches"), entry("color")] }; + h.app.ui.docking = Some(layout); + h.frames(3); + let before = h.host.borrow().windows[&viewport].rect; + h.app.ui_ctx = None; + h.app.run("window.panel.float", json!({"panel": "swatches", "group": true, "width": 400})).unwrap(); + h.frames(3); + assert_eq!(h.viewport("color"), viewport); + assert_ne!(h.viewport("swatches"), viewport, "the entry floats in a window of its own"); + assert_eq!(h.host.borrow().windows[&viewport].rect, before, "the accordion's window keeps its place and size"); +} + +#[test] +fn a_deferred_group_float_of_a_tab_group_resizes_its_native_window() { + let mut h = Harness::new(); + let viewport = native_tab_group(&mut h); + let id = floating_window(&layout_of(&h.app.ui), "swatches").unwrap().id; + let before = h.host.borrow().windows[&viewport].rect; + h.app.ui_ctx = None; + h.app.run("window.panel.float", json!({"panel": "swatches", "group": true, "width": 400})).unwrap(); + h.frames(3); + assert_eq!(floating_window(&layout_of(&h.app.ui), "swatches").unwrap().id, id); + assert_eq!(h.viewport("color"), viewport); + assert_eq!(h.host.borrow().windows[&viewport].rect, Rect::from_min_size(before.min, vec2(400.0, before.height()))); +} + +#[test] +fn deferred_native_geometry_does_not_show_panels_hidden_before_it_applies() { + let mut h = Harness::new(); + h.float("swatches"); + h.app.ui_ctx = None; + h.app.run("window.panel.float", json!({"panel": "swatches", "width": 350})).unwrap(); + h.app.run("window.panels", json!({})).unwrap(); + assert!(!h.app.ui.dock); + h.frames(3); + assert!(!h.app.ui.dock, "the panels stay hidden"); + assert_eq!(floating_window(&layout_of(&h.app.ui), "swatches").and_then(|w| w.native).map(|n| n[2]), Some(350.0)); +} + #[test] fn a_floated_panel_opens_its_own_os_window_where_the_backend_has_viewports() { let mut h = Harness::new(); diff --git a/docs/mcp.md b/docs/mcp.md index 3cb8d1d239..ca9a95037e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5935,9 +5935,13 @@ and several can be open at once. `window.swatchLibrary {library}`, `window.graph `{open, panel, name, count}`; `library: null` closes every panel of that kind. The panel id is `library::` (`library:swatches:pastels`, `library:graphicStyles:hand-drawn`, `library:swatches:loaded/C:/Palettes/Brand.ase`), and the panel commands take it like any other panel's: -`window.panel.float {panel, onto?, x?, y?, width?, height?}` groups, moves or resizes it. Supplied -geometry also updates an existing native panel window. Positions are relative to the main window's -content origin; omitted coordinates and dimensions keep the native window's current values. +`window.panel.float {panel, onto}` makes it a tab of the floating group holding `onto`, and +`window.panel.float {panel, x?, y?, width?, height?}` moves or resizes it; `onto` takes no geometry. +Positions are relative to the main window's content origin. When the panel is alone in a native panel +window, or `column: true` (or `group: true` on a tab group that fills the window) names the whole window, +supplied geometry updates that window and omitted coordinates and dimensions keep its current values. +A panel that shares a native window with other panels floats into a new window instead, which takes the +supplied geometry, and the shared window keeps the other panels, its place and its size. `window.panel.dock {panel}` docks it, `window.panel.close {panel}` closes it. `window.swatchLibrary.other {path}`, `window.graphicStyleLibrary.other {path}`, `window.symbolLibrary.other {path}` and `window.brushLibrary.other {path}` load a file and open it the same