mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
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.
This commit is contained in:
5 files changed
+74
-6
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -867,7 +867,8 @@ fn native_float_geometry(app: &VectorcraftApp, command: &mut DockCommand<String>
|
||||
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<String>
|
||||
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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
+7
-3
@@ -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:<kind>:<library id>` (`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
|
||||
|
||||
Reference in new issue
Block a user