mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 23:31:18 +00:00
Merge pull request #8411 from dotCooCoo/fix/native-panel-command-geometry
Panels: update native floating window geometry
This commit is contained in:
@@ -688,7 +688,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. `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; 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}",
|
||||
),
|
||||
(
|
||||
"window.panel.dock",
|
||||
|
||||
@@ -689,7 +689,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. `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; 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}",
|
||||
),
|
||||
(
|
||||
"window.panel.dock",
|
||||
|
||||
@@ -45,6 +45,8 @@ pub(crate) const PANEL_MIN_WIDTH: f32 = 220.0;
|
||||
/// Docking state that lives for the session only.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Runtime {
|
||||
/// Geometry commands waiting for the main window's desktop origin, by floating window id.
|
||||
native_geometry: BTreeMap<u64, (u64, Value)>,
|
||||
/// Where the dock area floats panels, as it was last drawn.
|
||||
space: Option<FloatSpace<String>>,
|
||||
/// A panel a command showed: its floating window comes forward on the next frame.
|
||||
@@ -745,7 +747,7 @@ fn shared_command_with(app: &mut VectorcraftApp, id: &str, params: &Value, legac
|
||||
if let Some(fields) = params.as_object_mut() {
|
||||
fields.insert("command".into(), Value::String(id.to_owned()));
|
||||
}
|
||||
let command: DockCommand<String> = serde_json::from_value(params).map_err(|e| e.to_string())?;
|
||||
let mut command: DockCommand<String> = serde_json::from_value(params).map_err(|e| e.to_string())?;
|
||||
match &command {
|
||||
DockCommand::Workspace { name } => return app.run("window.workspace", json!({"name": name})),
|
||||
DockCommand::NewWorkspace { name } => return app.run("window.workspace.new", json!({"name": name})),
|
||||
@@ -788,6 +790,7 @@ fn shared_command_with(app: &mut VectorcraftApp, id: &str, params: &Value, legac
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
let native = if legacy.is_none() { native_float_geometry(app, &mut command, &txn.workspace.layout) } else { None };
|
||||
let mut actions = match (&command, &legacy) {
|
||||
(DockCommand::Float { panel, group, .. } | DockCommand::Dock { panel, group, .. }, Some(legacy)) => {
|
||||
legacy.actions(&txn.workspace.layout, panel, *group)?
|
||||
@@ -817,7 +820,77 @@ fn shared_command_with(app: &mut VectorcraftApp, id: &str, params: &Value, legac
|
||||
for action in actions {
|
||||
closed.extend(txn.apply(action)?);
|
||||
}
|
||||
Ok(txn.commit(app, closed, reveal))
|
||||
if let Some(NativeFloatGeometry::Ready { panel, rect, .. }) = &native {
|
||||
closed.extend(txn.apply(Action::SetNative { panel: panel.clone(), rect: Some(*rect) })?);
|
||||
}
|
||||
let result = txn.commit(app, closed, reveal);
|
||||
match native {
|
||||
Some(NativeFloatGeometry::Deferred { window, params }) => {
|
||||
let layout = layout_of(&app.ui);
|
||||
app.dock_rt
|
||||
.native_geometry
|
||||
.retain(|id, (generation, _)| *generation == app.ui.docking_generation && layout.floating.iter().any(|window| window.id == *id));
|
||||
app.dock_rt.native_geometry.insert(window, (app.ui.docking_generation, params));
|
||||
}
|
||||
Some(NativeFloatGeometry::Ready { window, .. }) => {
|
||||
app.dock_rt.native_geometry.remove(&window);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
enum NativeFloatGeometry {
|
||||
Ready { window: u64, panel: String, rect: [f32; 4] },
|
||||
Deferred { window: u64, params: Value },
|
||||
}
|
||||
|
||||
fn native_float_geometry(app: &VectorcraftApp, command: &mut DockCommand<String>, layout: &Layout<String>) -> Option<NativeFloatGeometry> {
|
||||
let DockCommand::Float { panel, x, y, width, height, group, column } = command else { return None };
|
||||
if [*x, *y, *width, *height].iter().all(Option::is_none) {
|
||||
return None;
|
||||
}
|
||||
let window = floating_window(layout, panel)?;
|
||||
let whole = *column || window.panels().count() == 1 || (*group && matches!(window.root, Node::Tabs { .. } | Node::Stack { .. }));
|
||||
if !whole {
|
||||
return None;
|
||||
}
|
||||
let [old_x, old_y, old_width, old_height] = window.native?;
|
||||
if let Some((_, params)) = app.dock_rt.native_geometry.get(&window.id).filter(|(generation, _)| *generation == app.ui.docking_generation) {
|
||||
let previous = |name| params.get(name).and_then(Value::as_f64).map(|value| value as f32);
|
||||
*x = x.or_else(|| previous("x"));
|
||||
*y = y.or_else(|| previous("y"));
|
||||
*width = width.or_else(|| previous("width"));
|
||||
*height = height.or_else(|| previous("height"));
|
||||
}
|
||||
let origin = app
|
||||
.ui_ctx
|
||||
.as_ref()
|
||||
.and_then(|ctx| ctx.input(|input| input.raw.viewports.get(&egui::ViewportId::ROOT).and_then(|v| v.inner_rect)))
|
||||
.map(|rect| rect.min)
|
||||
.filter(|origin| origin.is_finite());
|
||||
let Some(origin) = origin else {
|
||||
let mut params = app
|
||||
.dock_rt
|
||||
.native_geometry
|
||||
.get(&window.id)
|
||||
.filter(|(generation, _)| *generation == app.ui.docking_generation)
|
||||
.map_or_else(|| json!({}), |(_, params)| params.clone());
|
||||
let fields = params.as_object_mut()?;
|
||||
fields.insert("panel".into(), json!(panel));
|
||||
fields.insert("group".into(), json!(group));
|
||||
fields.insert("column".into(), json!(column));
|
||||
for (name, value) in [("x", *x), ("y", *y), ("width", *width), ("height", *height)] {
|
||||
if let Some(value) = value {
|
||||
fields.insert(name.into(), json!(value));
|
||||
}
|
||||
}
|
||||
return Some(NativeFloatGeometry::Deferred { window: window.id, params });
|
||||
};
|
||||
// Native windows report desktop coordinates; float commands use the main window's points.
|
||||
let rect =
|
||||
[*x.get_or_insert(old_x - origin.x), *y.get_or_insert(old_y - origin.y), *width.get_or_insert(old_width), *height.get_or_insert(old_height)];
|
||||
Some(NativeFloatGeometry::Ready { window: window.id, panel: panel.clone(), rect: [origin.x + rect[0], origin.y + rect[1], rect[2], rect[3]] })
|
||||
}
|
||||
|
||||
/// One action from the renderer: the user's own gesture.
|
||||
@@ -1128,6 +1201,23 @@ fn known(action: &Action<String>) -> bool {
|
||||
pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
|
||||
let area = area_id();
|
||||
let ctx = ui.ctx().clone();
|
||||
let origin = ctx.input(|input| input.raw.viewports.get(&egui::ViewportId::ROOT).and_then(|v| v.inner_rect)).map(|rect| rect.min);
|
||||
if origin.is_some_and(|origin| origin.is_finite()) {
|
||||
for (window, (generation, mut params)) in std::mem::take(&mut app.dock_rt.native_geometry) {
|
||||
if generation != app.ui.docking_generation {
|
||||
continue;
|
||||
}
|
||||
let layout = layout_of(&app.ui);
|
||||
let panel = layout.floating.iter().find(|floating| floating.id == window).and_then(|floating| floating.panels().next()).cloned();
|
||||
let (Some(panel), Some(fields)) = (panel, params.as_object_mut()) else { continue };
|
||||
// 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));
|
||||
if let Err(error) = shared_command(app, "window.panel.float", ¶ms) {
|
||||
app.ui.status = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::tools_float::set_dock_area_left(&ctx, ui.available_rect_before_wrap().left());
|
||||
let changed_workspace = ctx.data_mut(|data| {
|
||||
let previous = data.get_temp::<u64>(area.with("generation"));
|
||||
|
||||
@@ -306,6 +306,58 @@ impl egui::DroppedFile for MockDrop {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_explicit_float_command_updates_an_existing_native_windows_geometry() {
|
||||
for mode in [json!({}), json!({"group": true}), json!({"column": true})] {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("window.panel.float", json!({"panel": "swatches", "x": 240, "y": 160, "width": 320, "height": 360})).unwrap();
|
||||
h.frames(3);
|
||||
let viewport = h.viewport("swatches");
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect, Rect::from_min_size(ORIGIN + vec2(240.0, 160.0), vec2(320.0, 360.0)));
|
||||
let mut params = json!({"panel": "swatches", "x": 280, "y": 190, "width": 350, "height": 390});
|
||||
params.as_object_mut().unwrap().extend(mode.as_object().unwrap().clone());
|
||||
h.app.run("window.panel.float", params).unwrap();
|
||||
h.frames(3);
|
||||
assert_eq!(h.viewport("swatches"), viewport);
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect, Rect::from_min_size(ORIGIN + vec2(280.0, 190.0), vec2(350.0, 390.0)));
|
||||
let moved = Rect::from_min_size(pos2(-500.0, 120.0), vec2(380.0, 410.0));
|
||||
h.host.borrow_mut().windows.get_mut(&viewport).unwrap().rect = moved;
|
||||
h.frames(3);
|
||||
let mut params = json!({"panel": "swatches", "width": 400});
|
||||
params.as_object_mut().unwrap().extend(mode.as_object().unwrap().clone());
|
||||
h.app.run("window.panel.float", params).unwrap();
|
||||
h.frames(3);
|
||||
let resized = Rect::from_min_size(moved.min, vec2(400.0, moved.height()));
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect, resized);
|
||||
let mut params = json!({"panel": "swatches"});
|
||||
params.as_object_mut().unwrap().extend(mode.as_object().unwrap().clone());
|
||||
h.app.run("window.panel.float", params).unwrap();
|
||||
h.frames(3);
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect, resized);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_native_geometry_updates_before_viewport_metadata_is_available() {
|
||||
let mut h = Harness::new();
|
||||
let viewport = h.float("swatches");
|
||||
h.app.ui_ctx = None;
|
||||
h.app.run("window.panel.float", json!({"panel": "swatches", "x": 280, "y": 190, "height": 390})).unwrap();
|
||||
h.app.run("window.panel.float", json!({"panel": "swatches", "width": 350})).unwrap();
|
||||
h.frames(3);
|
||||
assert_eq!(h.viewport("swatches"), viewport);
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect, Rect::from_min_size(ORIGIN + vec2(280.0, 190.0), vec2(350.0, 390.0)));
|
||||
h.app.run("window.panel.float", json!({"panel": "color", "onto": "swatches"})).unwrap();
|
||||
h.frames(3);
|
||||
h.app.ui_ctx = None;
|
||||
h.app.run("window.panel.float", json!({"panel": "swatches", "column": true, "x": 480, "y": 260})).unwrap();
|
||||
h.app.run("window.panel.dock", json!({"panel": "swatches", "anchor": "layers", "zone": "tab"})).unwrap();
|
||||
h.frames(3);
|
||||
assert!(!floats(&h.app.ui, "swatches"));
|
||||
assert_eq!(h.viewport("color"), viewport);
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect.min, ORIGIN + vec2(480.0, 260.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_floated_panel_opens_its_own_os_window_where_the_backend_has_viewports() {
|
||||
let mut h = Harness::new();
|
||||
|
||||
+4
-1
@@ -5440,7 +5440,10 @@ 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?}` groups or moves it, `window.panel.dock {panel}` docks it,
|
||||
`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.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
|
||||
way.
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
## Feature submission evidence
|
||||
|
||||
`window.panel.float` updates an existing native panel window's supplied position and size (#8391). Positions use the main window's content origin. Omitted coordinates and dimensions keep their current native values, including after an OS window move or resize. Evidence: `panel_docking::native_tests::an_explicit_float_command_updates_an_existing_native_windows_geometry` covers panel, group and column commands. Scores and estimates are unchanged.
|
||||
|
||||
EPS embedded fonts, 2026-11-09 (#6023–#6067): the fonts an EPS carries draw their glyphs instead of being set as type in an installed font: composite (Type 0) fonts with the 8/8 mapping, plain Type 42 fonts (characters from their glyph names or character map, widths from the font), CID-keyed fonts over CMaps (Type 0 and Type 2 CIDFonts, CIDFonts in a FontSet's Compact Font Format data, base-font CMaps, named CIDFonts over predefined Unicode CMaps set as type) and embedded Type 1 fonts; the show operators' spacing along the baseline is kept as tracking, `kshow` included. Each step is charged to the interpreter's budgets. Hand-written test files only (no corpus file uses these fonts); scores and estimates unchanged. Evidence: `crates/eps/src/import/tests_composite.rs`, `tests_type42.rs`, `tests_cid.rs`, `tests_type1.rs`; details in [file-format-parity.md](file-format-parity.md).
|
||||
|
||||
Numeric fields step on wheel hover without taking keyboard focus (#5949). Arrow keys still require focus; modifiers, units, limits, mixed values and existing rounding stay in the shared stepping path. Headless regressions in `tests/numfields.rs` cover hovered unfocused fields, focused fields, trackpad accumulation and panel scroll exclusion. A canvas-first/panel-second regression also checks that a field turn cannot start a canvas zoom glide when the pointer enters the canvas on the next frame. Scores and estimates unchanged.
|
||||
|
||||
Reference in New Issue
Block a user