From 8e16c05cbb1e3cf609cef990bf4f94ccd359a20c Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 25 Oct 2026 00:34:42 +0000 Subject: [PATCH] Docking: a panel whose saved place is gone opens beside the photo on its side When a hidden panel's anchor is neither shown nor hidden, craft-ui falls back to the given anchor's tabs. The photo view is that anchor and takes no tabs, so the panel opens beside it on its default side instead of at the right edge. Test: Library anchored on an absent Presets opens to the left of the photo. --- crates/ui-egui/src/docking.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/docking.rs b/crates/ui-egui/src/docking.rs index be4c9d060..6feebe5cb 100644 --- a/crates/ui-egui/src/docking.rs +++ b/crates/ui-egui/src/docking.rs @@ -132,7 +132,9 @@ fn set_visible(workspace: &mut Workspace, panel: Panel, visible: bool) -> Result // beside the photo instead. if workspace.hidden.iter().any(|(hidden, _)| *hidden == panel) { let mut next = workspace.clone(); - if next.set_visible(panel, true, None, permissions).is_ok() && validate(&next).is_ok() { + // A saved place that can't be rebuilt falls back to joining the fallback's tabs. The + // photo view takes no tabs, so that is refused and the panel opens beside it below. + if next.set_visible(panel, true, Some(Panel::Canvas), permissions).is_ok() && validate(&next).is_ok() { *workspace = next; return Ok(()); } @@ -604,4 +606,25 @@ mod tests { assert_eq!((location.anchor, location.placement), (Some(Panel::Canvas), Placement::Split(zone)), "{panel:?}"); } } + + #[test] + fn a_panel_whose_saved_place_is_gone_opens_beside_the_photo_on_its_side() { + let root = split(SplitAxis::Horizontal, SplitSize::FixedSecond(300.0), tabs(Panel::Canvas), tabs(Panel::Tools)); + let mut workspace = Workspace::new(Layout { root: Some(root), floating: Vec::new() }); + // Presets, the panel Library went back beside, is neither shown nor hidden. + let location: craft_ui::docking::Location = serde_json::from_value(json!({ + "floating": null, + "anchor": "presets", + "placement": {"Split": "Left"}, + "size": {"FixedFirst": 280.0}, + "stack": null, + "sibling": ["presets"] + })) + .unwrap(); + workspace.hidden.push((Panel::Library, location)); + validate(&workspace).unwrap(); + set_visible(&mut workspace, Panel::Library, true).unwrap(); + let location = workspace.layout.location(&Panel::Library).unwrap(); + assert_eq!((location.anchor, location.placement), (Some(Panel::Canvas), Placement::Split(Zone::Left))); + } }