diff --git a/crates/ui/src/docking/command_tests.rs b/crates/ui/src/docking/command_tests.rs index 4f2be2f6..e109a08c 100644 --- a/crates/ui/src/docking/command_tests.rs +++ b/crates/ui/src/docking/command_tests.rs @@ -359,4 +359,15 @@ fn float_without_a_rect_takes_the_drag_size_inside_the_dock_area() { let small = FloatSpace::new(egui::Rect::from_min_size(egui::pos2(0.0, 30.0), egui::vec2(200.0, 200.0))); let applied = parse(json!({"command": "window.panel.float", "panel": "layers", "group": true})).unwrap().to_actions(&workspace(), false, &small); assert_eq!(applied, Ok(vec![Action::MoveGroup { panel: s("layers"), to: Target::Float { rect: Some([0.0, 30.0, 200.0, 200.0]) } }])); + + // A host seeds the size of a panel the area never drew; a recorded size still wins. + let seeded = FloatSpace::new(area).with_panel_size(s("layers"), egui::vec2(180.0, 240.0)); + let applied = parse(json!({"command": "window.panel.float", "panel": "layers"})).unwrap().to_actions(&workspace(), false, &seeded); + assert_eq!(applied, Ok(vec![Action::Float { panel: s("layers"), rect: [24.0, 54.0, 180.0, 240.0] }])); + let recorded = space.clone().with_panel_size(s("layers"), egui::vec2(180.0, 240.0)); + assert_eq!(float_with(&recorded, "layers"), vec![Action::Float { panel: s("layers"), rect: [24.0, 54.0, 200.0, 150.0] }]); +} + +fn float_with(space: &FloatSpace
, panel: &str) -> Vec {
pub fn new(area: Rect) -> Self {
Self { area, panels: Vec::new(), groups: Vec::new(), columns: Vec::new() }
}
+
+ /// Adds the size a command floats `panel` at alone when the area has not drawn it, such as
+ /// a hidden panel or a headless run. A size the area recorded for the panel takes precedence.
+ pub fn with_panel_size(mut self, panel: P, size: Vec2) -> Self {
+ self.panels.push((panel, size));
+ self
+ }
}
/// Lookups for `DockCommand`, which needs feature `serde`.
diff --git a/docs/ui-docking.md b/docs/ui-docking.md
index 3dd46036..9705a620 100644
--- a/docs/ui-docking.md
+++ b/docs/ui-docking.md
@@ -191,7 +191,9 @@ let closed = command.apply(&mut app.workspace, style.right_to_left, &space, |pan
inside the dock area, 24 points from its top-left corner, so it stays clear of the menu bar.
The area records that geometry in a `FloatSpace` each frame; `float_space(ctx, id)` reads it
and `apply` and `to_actions` take it. Before the area has drawn, `FloatSpace::new(area)` floats
- a panel at 260x320 and a group or column at its column width by 320. `x`, `y`, `width` and
+ a panel at 260x320 and a group or column at its column width by 320.
+ `FloatSpace::with_panel_size(panel, size)` gives a panel the area has not drawn (a hidden
+ panel, a headless run) the host's own size; a size the area recorded wins. `x`, `y`, `width` and
`height` replace the matching values, and a group or column that is already a whole floating
window keeps its rect.
- Without a value, `minimized`, `iconic` and `locked` toggle.