LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Docking: side panels in dock columns; saved split-frame layouts reset once
aiongg8ae15d4f5e89
diff --git a/apps/lightcraft/src/main.rs b/apps/lightcraft/src/main.rsindex 0cab9e189..b971e5519 100644--- a/apps/lightcraft/src/main.rs+++ b/apps/lightcraft/src/main.rs@@ -259,10 +259,12 @@ fn load_prefs(in_memory: bool) -> (Option<UiState>, Option<String>, bool) {load_prefs_at(&path, !in_memory)}-/// Compatibility recovery is limited to persisted docking, not runtime UiState commands.+/// Compatibility recovery is limited to persisted docking, not runtime UiState commands. An+/// arrangement from an older docking version starts again from the default without a warning.fn decode_saved_ui(bytes: &[u8]) -> Result<(UiState, bool), String> {let mut saved: serde_json::Value = serde_json::from_slice(bytes).map_err(|error| error.to_string())?;let fields = saved.as_object_mut().ok_or("settings must be an object")?;+ lightcraft_ui_egui::docking::drop_outdated(fields);let recovered =fields.get("docking").is_some_and(|value| match serde_json::from_value::<Option<lightcraft_ui_egui::docking::Workspace>>(value.clone()) {Ok(Some(workspace)) => lightcraft_ui_egui::docking::validate(&workspace).is_err(),diff --git a/crates/ui-egui/src/docking.rs b/crates/ui-egui/src/docking.rsindex 6feebe5cb..59c00b0f6 100644--- a/crates/ui-egui/src/docking.rs+++ b/crates/ui-egui/src/docking.rs@@ -2,8 +2,8 @@//! Document contents remain owned by their existing view implementations.use craft_ui::docking::{- Action, DockArea, DockCommand, DockError, DockOperation, DockStyle, FloatSpace, Layout, Node, PanelLimits, PanelState, Permissions, Placement,- UiDock, Zone,+ Action, Column, ColumnLocation, DockArea, DockCommand, DockError, DockOperation, DockStyle, FloatSpace, Group, GroupLocation, Layout, Location,+ Node, PanelLimits, PanelState, Permissions, Placement, Side, UiDock, Zone,};use craft_ui::layout::{SplitAxis, SplitSize};use serde::{Deserialize, Serialize};@@ -36,16 +36,38 @@ impl Panel {Self::Presets => "Presets",}}- fn default_side(self) -> Zone {+ /// The dock the panel opens in when it has no recorded place.+ fn home_side(self) -> Side {+ if self == Self::Library { Side::Start } else { Side::End }+ }+ /// The width of the panel's own column in the default workspace.+ fn home_width(self) -> f32 {match self {- Self::Canvas => Zone::Right,- Self::Library => Zone::Left,- Self::Tools => Zone::Right,- Self::Presets => Zone::Right,+ Self::Canvas => crate::state::MIN_PHOTO_WIDTH,+ Self::Library => crate::state::LEFT_WIDTH.default,+ Self::Tools => crate::state::RIGHT_WIDTH.default,+ Self::Presets => PRESETS_WIDTH,}}}+const PRESETS_WIDTH: f32 = 300.0;++/// The arrangement generation saved as `UiState::docking_version`. Settings without it hold the+/// side panels in split frames; they start again from [`default_workspace`].+pub const DOCKING_VERSION: u32 = 1;++/// Drops saved settings' arrangement from before [`DOCKING_VERSION`], with the places of its+/// closed panels, so the app starts from the default workspace; every other setting stays.+/// Returns true when an arrangement was dropped.+pub fn drop_outdated(settings: &mut serde_json::Map<String, Value>) -> bool {+ if settings.get("dockingVersion").and_then(Value::as_u64).is_some_and(|version| version >= u64::from(DOCKING_VERSION)) {+ return false;+ }+ settings.insert("dockingVersion".into(), json!(DOCKING_VERSION));+ settings.remove("docking").is_some_and(|docking| !docking.is_null())+}+fn permissions(panel: &Panel) -> Permissions {// Panels open and split beside the photo view, but never join it as tabs.if *panel == Panel::Canvas { Permissions { accepts_splits: true, ..Permissions::PROTECTED } } else { Permissions::default() }@@ -62,23 +84,49 @@ fn split(axis: SplitAxis, size: SplitSize, first: Node<Panel>, second: Node<Pane/// The saved arrangement. Closed panels keep their last group, side, size or floating rect.pub type Workspace = craft_ui::docking::Workspace<Panel>;-pub fn default_workspace() -> Workspace {+fn column(panel: Panel, width: f32) -> Column<Panel> {+ Column::new(vec![Group::new(vec![panel], 0)], width)+}++/// Library in a start dock and Tools in an end dock beside the photo. Presets has a column of+/// its own on Tools' photo side rather than a group under Tools: both are tall lists that are+/// read side by side while trying presets, and stacking them would halve both.+fn docked(left: f32, right: f32) -> Workspace {+ let start = Node::Dock { side: Side::Start, columns: vec![column(Panel::Library, left)] };+ let end = Node::Dock { side: Side::End, columns: vec![column(Panel::Tools, right), column(Panel::Presets, PRESETS_WIDTH)] };Workspace::new(Layout {root: Some(split(SplitAxis::Horizontal,- SplitSize::FixedFirst(crate::state::LEFT_WIDTH.default),- tabs(Panel::Library),- split(- SplitAxis::Horizontal,- SplitSize::FixedSecond(crate::state::RIGHT_WIDTH.default),- split(SplitAxis::Horizontal, SplitSize::FixedSecond(300.0), tabs(Panel::Canvas), tabs(Panel::Presets)),- tabs(Panel::Tools),- ),+ SplitSize::FixedFirst(left),+ start,+ split(SplitAxis::Horizontal, SplitSize::FixedSecond(right + PRESETS_WIDTH), tabs(Panel::Canvas), end),)),floating: Vec::new(),})}+pub fn default_workspace() -> Workspace {+ docked(crate::state::LEFT_WIDTH.default, crate::state::RIGHT_WIDTH.default)+}++/// Where a panel without a usable recorded place opens: its own column at its dock's window+/// edge, or Presets on the photo side of Tools while Tools is in the end dock.+fn home(workspace: &Workspace, panel: Panel) -> Location<Panel> {+ let column = ColumnLocation { side: panel.home_side(), width: panel.home_width(), iconic: false, iconic_width: None };+ let docked_at =+ |other: Panel| workspace.layout.location(&other).ok().and_then(|location| location.group).and_then(|group| group.column).map(|c| c.side);+ let beside = (panel == Panel::Presets && docked_at(Panel::Tools) == Some(Side::End)).then_some(Panel::Tools);+ Location {+ floating: None,+ anchor: beside,+ placement: if beside.is_some() { Placement::Column { after: true } } else { Placement::Tab { before: None } },+ size: None,+ stack: None,+ sibling: Vec::new(),+ group: Some(GroupLocation { minimized: false, height: None, column: Some(column) }),+ }+}+fn error(error: DockError) -> String {error.to_string()}@@ -118,7 +166,7 @@ fn apply(workspace: &mut Workspace, action: Action<Panel>) -> Result<(), String>Ok(())}-/// Shows a panel at its recorded place, else beside the photo on its usual side. A panel that+/// Shows a panel at its recorded place, else in its dock column ([`home`]). A panel that/// already has the asked visibility keeps its tab selection.fn set_visible(workspace: &mut Workspace, panel: Panel, visible: bool) -> Result<(), String> {if workspace.layout.contains(&panel) == visible {@@ -128,18 +176,23 @@ fn set_visible(workspace: &mut Workspace, panel: Panel, visible: bool) -> Resultreturn apply(workspace, Action::Close { panel });}validate(workspace)?;- // Without a recorded place craft-ui opens the panel at the right edge; LightCraft puts it- // beside the photo instead.+ // A recorded 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 goes to its home column below.if workspace.hidden.iter().any(|(hidden, _)| *hidden == panel) {let mut next = workspace.clone();- // 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(());}}- apply(workspace, Action::OpenAt { panel, anchor: Panel::Canvas, placement: Placement::Split(panel.default_side()) })+ let mut next = workspace.clone();+ next.hidden.retain(|(hidden, _)| *hidden != panel);+ let location = home(&next, panel);+ next.hidden.push((panel, location));+ next.set_visible(panel, true, Some(Panel::Canvas), permissions).map_err(error)?;+ validate(&next)?;+ *workspace = next;+ Ok(())}/// Membership is passive state; an explicit command also exposes the panel's body.@@ -177,14 +230,7 @@ fn run(workspace: &mut Workspace, params: &Value) -> Result<(), String> {}fn from_ui(app: &crate::LightcraftApp) -> Workspace {- let mut workspace = default_workspace();- if let Some(Node::Split { size, second, .. }) = workspace.layout.root.as_mut() {- *size = SplitSize::FixedFirst(crate::state::LEFT_WIDTH.clamp(app.ui.left_width));- if let Node::Split { size, .. } = second.as_mut() {- *size = SplitSize::FixedSecond(crate::state::RIGHT_WIDTH.clamp(app.ui.right_width));- }- }- workspace+ docked(crate::state::LEFT_WIDTH.clamp(app.ui.left_width), crate::state::RIGHT_WIDTH.clamp(app.ui.right_width))}fn sync(workspace: &mut Workspace, app: &crate::LightcraftApp) -> Result<(), String> {@@ -207,10 +253,12 @@ fn publish_visibility(app: &mut crate::LightcraftApp, workspace: &Workspace) {let Ok(location) = workspace.layout.location(&panel) else {continue;};- let value = match (location.floating, location.placement, location.size) {- (Some([_, _, width, _]), _, _)- | (None, Placement::Split(Zone::Left), Some(SplitSize::FixedFirst(width)))- | (None, Placement::Split(Zone::Right), Some(SplitSize::FixedSecond(width))) => Some(width),+ let column = location.group.and_then(|group| group.column);+ let value = match (location.floating, column, location.placement, location.size) {+ (Some([_, _, width, _]), ..) => Some(width),+ (None, Some(column), ..) => Some(column.width),+ (None, None, Placement::Split(Zone::Left), Some(SplitSize::FixedFirst(width)))+ | (None, None, Placement::Split(Zone::Right), Some(SplitSize::FixedSecond(width))) => Some(width),// A vertical split stores height, and the opposite fixed side sizes a sibling._ => None,};@@ -305,8 +353,10 @@ pub fn show(app: &mut crate::LightcraftApp, ui: &mut egui::Ui) {app.ui.docking = Some(workspace.clone());let mut style = DockStyle::from_ui(ui);style.min_pane = 96.0;- // The side panels are frames whose widths LightCraft tracks; dock columns are not offered.- style.new_dock_zones = false;+ // Free docking: a panel dropped at an empty window edge makes a dock, and the photo takes+ // drops on all four sides.+ style.new_dock_zones = true;+ style.side_edge_zones = false;style.float_label = crate::i18n::tr("Float panel").into();style.close_label = crate::i18n::tr("Close panel").into();style.move_panel_to_label = crate::i18n::tr("Move to group").into();@@ -320,6 +370,12 @@ pub fn show(app: &mut crate::LightcraftApp, ui: &mut egui::Ui) {style.close_others_label = crate::i18n::tr("Close other panels in group").into();style.minimize_label = crate::i18n::tr("Minimize").into();style.expand_label = crate::i18n::tr("Expand").into();+ style.move_column_label = crate::i18n::tr("Move panel column").into();+ style.collapse_to_icons_label = crate::i18n::tr("Collapse to Icons").into();+ style.expand_panels_label = crate::i18n::tr("Expand Panels").into();+ style.collapse_column_label = crate::i18n::tr("Collapse column").into();+ style.expand_column_label = crate::i18n::tr("Expand column").into();+ style.auto_collapse_label = crate::i18n::tr("Auto-Collapse Iconic Panels").into();style.move_window_label = crate::i18n::tr("Move panel window").into();style.close_window_label = crate::i18n::tr("Close panel window").into();style.float_hint_label = crate::i18n::tr("Hold {key} to undock").into();@@ -399,7 +455,8 @@ pub fn show(app: &mut crate::LightcraftApp, ui: &mut egui::Ui) {}}-/// Keep the established ui.set width controls connected to the panel's current parent split.+/// Keep the established ui.set width controls connected to the panel's dock column, floating+/// window or parent split.pub(crate) fn set_widths(state: &mut crate::UiState, params: &Value) -> Result<(), String> {state.left_width = crate::state::LEFT_WIDTH.clamp(state.left_width);state.right_width = crate::state::RIGHT_WIDTH.clamp(state.right_width);@@ -415,6 +472,10 @@ pub(crate) fn set_widths(state: &mut crate::UiState, params: &Value) -> Result<(if let Some(rect) = &mut location.floating {rect[2] = width;}+ if let Some(column) = location.group.as_mut().and_then(|group| group.column.as_mut()) {+ column.width = width;+ continue;+ }match location.placement {Placement::Split(Zone::Left) => location.size = Some(SplitSize::FixedFirst(width)),Placement::Split(Zone::Right) => location.size = Some(SplitSize::FixedSecond(width)),@@ -428,6 +489,10 @@ pub(crate) fn set_widths(state: &mut crate::UiState, params: &Value) -> Result<(apply(workspace, Action::MoveFloating { panel, rect })?;continue;}+ if workspace.layout.location(&panel).is_ok_and(|location| location.group.is_some_and(|group| group.column.is_some())) {+ apply(workspace, Action::ResizeColumn { panel, width })?;+ continue;+ }let mut nodes = workspace.layout.root.as_ref().map(|node| vec![(node, Vec::new())]).unwrap_or_default();let mut change = None;while let Some((node, path)) = nodes.pop() {@@ -470,6 +535,23 @@ fn panel_limits(panel: &Panel) -> PanelLimits {PanelLimits { min, max: egui::vec2(max_width, 1_000_000.0) }}+/// The columns of the dock on `side`, from the window edge inwards: width and the panels of+/// each group.+#[cfg(test)]+pub(crate) fn columns(workspace: &Workspace, side: Side) -> Vec<(f32, Vec<Vec<Panel>>)> {+ let mut nodes: Vec<_> = workspace.layout.root.iter().collect();+ while let Some(node) = nodes.pop() {+ match node {+ Node::Split { first, second, .. } => nodes.extend([&**first, &**second]),+ Node::Dock { side: dock, columns } if *dock == side => {+ return columns.iter().map(|column| (column.width, column.groups.iter().map(|group| group.panels.clone()).collect())).collect();+ }+ _ => {}+ }+ }+ Vec::new()+}+#[cfg(test)]mod tests {use super::*;@@ -533,7 +615,7 @@ mod tests {}#[test]- fn legacy_width_publication_reads_own_horizontal_and_floating_widths() {+ fn legacy_width_publication_reads_own_split_and_floating_widths() {for (size, first) in [(SplitSize::FixedFirst(310.0), true), (SplitSize::FixedSecond(310.0), false)] {let workspace = tools_split(SplitAxis::Horizontal, size, first);let mut app = app_with_widths();@@ -597,18 +679,125 @@ mod tests {}#[test]- fn a_panel_without_a_recorded_place_opens_beside_the_photo_on_its_side() {- for (panel, zone) in [(Panel::Library, Zone::Left), (Panel::Presets, Zone::Right)] {- 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() });- set_visible(&mut workspace, panel, true).unwrap();- let location = workspace.layout.location(&panel).unwrap();- assert_eq!((location.anchor, location.placement), (Some(Panel::Canvas), Placement::Split(zone)), "{panel:?}");+ fn default_workspace_docks_library_at_the_start_and_tools_and_presets_at_the_end() {+ let workspace = default_workspace();+ validate(&workspace).unwrap();+ assert_eq!(columns(&workspace, Side::Start), [(crate::state::LEFT_WIDTH.default, vec![vec![Panel::Library]])]);+ assert_eq!(+ columns(&workspace, Side::End),+ [(crate::state::RIGHT_WIDTH.default, vec![vec![Panel::Tools]]), (PRESETS_WIDTH, vec![vec![Panel::Presets]])],+ "Presets has its own column on Tools' photo side"+ );+ let Some(Node::Split { second, .. }) = &workspace.layout.root else { panic!("{:?}", workspace.layout.root) };+ let Node::Split { first, .. } = &**second else { panic!("{second:?}") };+ assert_eq!(**first, tabs(Panel::Canvas), "the photo sits between the docks");+ assert!(workspace.layout.floating.is_empty());+ let app = app_with_widths();+ let workspace = from_ui(&app);+ assert_eq!(columns(&workspace, Side::Start).first().map(|column| column.0), Some(333.0));+ assert_eq!(columns(&workspace, Side::End).first().map(|column| column.0), Some(410.0));+ }++ #[test]+ fn dock_column_widths_publish_and_follow_width_controls() {+ let mut app = app_with_widths();+ let workspace = docked(300.0, 310.0);+ publish_visibility(&mut app, &workspace);+ assert_eq!((app.ui.left_width, app.ui.right_width), (300.0, 310.0));+ let mut state = crate::UiState { docking: Some(workspace), left_width: 350.0, right_width: 400.0, ..Default::default() };+ set_visible(state.docking.as_mut().unwrap(), Panel::Library, false).unwrap();+ set_widths(&mut state, &json!({"leftWidth":350.0, "rightWidth":400.0})).unwrap();+ let workspace = state.docking.as_mut().unwrap();+ assert_eq!(columns(workspace, Side::End).first().map(|column| column.0), Some(400.0), "Tools' column");+ set_visible(workspace, Panel::Library, true).unwrap();+ assert_eq!(columns(workspace, Side::Start), [(350.0, vec![vec![Panel::Library]])], "the closed Library's column");+ }++ #[test]+ fn a_panel_without_a_recorded_place_opens_in_its_dock() {+ let root = split(+ SplitAxis::Horizontal,+ SplitSize::FixedSecond(300.0),+ tabs(Panel::Canvas),+ Node::Dock { side: Side::End, columns: vec![column(Panel::Tools, 300.0)] },+ );+ let mut workspace = Workspace::new(Layout { root: Some(root), floating: Vec::new() });+ set_visible(&mut workspace, Panel::Presets, true).unwrap();+ set_visible(&mut workspace, Panel::Library, true).unwrap();+ validate(&workspace).unwrap();+ assert_eq!(columns(&workspace, Side::Start), [(crate::state::LEFT_WIDTH.default, vec![vec![Panel::Library]])]);+ assert_eq!(columns(&workspace, Side::End), [(300.0, vec![vec![Panel::Tools]]), (PRESETS_WIDTH, vec![vec![Panel::Presets]])]);+ // Without Tools in the end dock, Presets takes the dock's window edge.+ let mut workspace = default_workspace();+ set_visible(&mut workspace, Panel::Presets, false).unwrap();+ workspace.hidden.clear();+ apply(&mut workspace, Action::Float { panel: Panel::Tools, rect: [12.0, 34.0, 390.0, 450.0] }).unwrap();+ set_visible(&mut workspace, Panel::Presets, true).unwrap();+ assert_eq!(columns(&workspace, Side::End), [(PRESETS_WIDTH, vec![vec![Panel::Presets]])]);+ }++ fn saved_settings(docking: Value, version: Option<u32>) -> serde_json::Map<String, Value> {+ let ui = crate::UiState { thumb_size: 210.0, filmstrip: false, presets: true, ..Default::default() };+ let mut saved = serde_json::to_value(&ui).unwrap();+ let fields = saved.as_object_mut().unwrap();+ fields.insert("docking".into(), docking);+ match version {+ Some(version) => fields.insert("dockingVersion".into(), json!(version)),+ None => fields.remove("dockingVersion"),+ };+ fields.clone()+ }++ #[test]+ fn a_saved_split_frame_layout_without_a_docking_version_loads_as_the_default_docks() {+ let frames = split(+ SplitAxis::Horizontal,+ SplitSize::FixedFirst(333.0),+ tabs(Panel::Library),+ split(SplitAxis::Horizontal, SplitSize::FixedSecond(410.0), tabs(Panel::Canvas), tabs(Panel::Tools)),+ );+ let frames = Workspace::new(Layout { root: Some(frames), floating: Vec::new() });+ validate(&frames).unwrap();+ for version in [None, Some(0)] {+ let mut fields = saved_settings(serde_json::to_value(&frames).unwrap(), version);+ assert!(drop_outdated(&mut fields));+ let ui: crate::UiState = serde_json::from_value(Value::Object(fields)).unwrap();+ assert!(ui.docking.is_none());+ assert_eq!(ui.docking_version, DOCKING_VERSION);+ assert_eq!((ui.thumb_size, ui.filmstrip, ui.presets), (210.0, false, true), "other settings stay");+ let mut app = app_with_widths();+ app.ui = ui;+ command(&mut app, false, &json!({"operation":"activate","panel":"tools"})).unwrap();+ let workspace = app.ui.docking.as_ref().unwrap();+ assert!(!workspace.layout.contains(&Panel::Library), "the Library panel stays closed");+ assert_eq!(+ columns(workspace, Side::End),+ [(crate::state::RIGHT_WIDTH.default, vec![vec![Panel::Tools]]), (PRESETS_WIDTH, vec![vec![Panel::Presets]])]+ );}}#[test]- fn a_panel_whose_saved_place_is_gone_opens_beside_the_photo_on_its_side() {+ fn a_saved_dock_layout_round_trips() {+ let mut workspace = default_workspace();+ apply(&mut workspace, Action::ResizeColumn { panel: Panel::Tools, width: 333.0 }).unwrap();+ apply(+ &mut workspace,+ Action::Move { panel: Panel::Presets, anchor: Panel::Library, placement: Placement::Group { below: true, height: None } },+ )+ .unwrap();+ set_visible(&mut workspace, Panel::Library, false).unwrap();+ let mut fields = saved_settings(serde_json::to_value(&workspace).unwrap(), Some(DOCKING_VERSION));+ assert!(!drop_outdated(&mut fields));+ let ui: crate::UiState = serde_json::from_value(Value::Object(fields)).unwrap();+ let loaded = ui.docking.unwrap();+ validate(&loaded).unwrap();+ assert_eq!(loaded, workspace);+ assert_eq!(serde_json::to_value(crate::UiState::default()).unwrap()["dockingVersion"], DOCKING_VERSION, "saves write the version");+ }++ #[test]+ fn a_panel_whose_saved_place_is_gone_opens_in_its_dock() {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.@@ -624,7 +813,7 @@ mod tests {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)));+ validate(&workspace).unwrap();+ assert_eq!(columns(&workspace, Side::Start), [(crate::state::LEFT_WIDTH.default, vec![vec![Panel::Library]])]);}}diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex 0bbd619d8..f9da46444 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -782,6 +782,9 @@ pub struct UiState {pub window: Option<crate::window_place::WindowPlace>,/// Shared panel arrangement; absent in legacy settings until their first layout.pub docking: Option<crate::docking::Workspace>,+ /// The arrangement generation `docking` was saved in ([`crate::docking::DOCKING_VERSION`]);+ /// settings files are read through [`crate::docking::drop_outdated`].+ pub docking_version: u32,#[serde(default = "crate::i18n::default_language")]pub language: crate::i18n::Locale,/// The Build Previews run last announced (its identity, finished?).@@ -1482,6 +1485,7 @@ impl Default for UiState {UiState {window: None,docking: None,+ docking_version: crate::docking::DOCKING_VERSION,language: crate::i18n::default_language(),preview_build_seen: None,unsaved_seen: false,diff --git a/crates/ui-egui/src/tests_docking_acceptance.rs b/crates/ui-egui/src/tests_docking_acceptance.rsindex 5e496b822..940451f19 100644--- a/crates/ui-egui/src/tests_docking_acceptance.rs+++ b/crates/ui-egui/src/tests_docking_acceptance.rs@@ -44,6 +44,30 @@ fn release(h: &mut Headless, pos: egui::Pos2) {h.step();}+#[test]+fn window_menu_reopens_closed_panels_in_their_dock_columns() {+ use craft_ui::docking::Side;+ let mut h = app();+ let columns = |h: &Headless, side| {+ crate::docking::columns(h.app.ui.docking.as_ref().unwrap(), side).into_iter().map(|(_, groups)| groups).collect::<Vec<_>>()+ };+ let end = vec![vec![vec![Panel::Tools]], vec![vec![Panel::Presets]]];+ h.app.run("panel.presets", json!({})).unwrap();+ h.step();+ assert_eq!(columns(&h, Side::End), end, "Presets opens on Tools' photo side");+ dock(&mut h, json!({"operation":"close","panel":"tools"}));+ assert_eq!(h.app.ui.right, RightPanel::None);+ h.app.run("panel.edit", json!({})).unwrap();+ h.step();+ assert_eq!(columns(&h, Side::End), end, "Tools reopens at the window edge");+ let width = crate::docking::columns(h.app.ui.docking.as_ref().unwrap(), Side::Start).first().unwrap().0;+ dock(&mut h, json!({"operation":"close","panel":"library"}));+ assert!(!h.app.ui.left_panel);+ h.app.run("view.leftPanel", json!({})).unwrap();+ h.step();+ assert_eq!(crate::docking::columns(h.app.ui.docking.as_ref().unwrap(), Side::Start), [(width, vec![vec![Panel::Library]])]);+}+#[test]fn inactive_same_mode_commands_reveal_without_closing_or_editing() {let mut h = app();@@ -271,8 +295,8 @@ fn covered_keyword_rejects_hierarchy_move_and_uncovered_target_moves_exact_keywo#[test]fn reset_during_held_divider_drag_keeps_replacement_layout_on_later_movement() {let mut h = app();- let divider = egui::Id::new("lightcraft-docking").with(("split", Vec::<bool>::new()));- let from = h.view.ctx.read_response(divider).expect("the custom workspace root divider is rendered").rect.center();+ let divider = egui::Id::new("lightcraft-docking").with(("column-resize", Some(Panel::Library)));+ let from = h.view.ctx.read_response(divider).expect("the Library column's divider is rendered").rect.center();let before = h.app.ui.docking.as_ref().unwrap().layout.clone();h.app.synthetic.push(Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });h.step();@@ -303,7 +327,7 @@ fn reset_during_held_divider_drag_keeps_replacement_layout_on_later_movement() {fn held_divider_replacement_route(route: &str) {let mut h = app();- let divider = egui::Id::new("lightcraft-docking").with(("split", Vec::<bool>::new()));+ let divider = egui::Id::new("lightcraft-docking").with(("column-resize", Some(Panel::Library)));let from = h.view.ctx.read_response(divider).unwrap().rect.center();let photos = serde_json::to_value(h.app.session.catalog.photos().map(|photo| photo.as_ref()).collect::<Vec<_>>()).unwrap();h.app.synthetic.push(Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });diff --git a/crates/ui-egui/tests/it/docking_workflows.rs b/crates/ui-egui/tests/it/docking_workflows.rsindex a8e6c3d51..1d360a6b2 100644--- a/crates/ui-egui/tests/it/docking_workflows.rs+++ b/crates/ui-egui/tests/it/docking_workflows.rs@@ -1,5 +1,5 @@//! Real library/tool panel moves preserve the selected tool and saved arrangement.-use craft_ui::docking::{DockArea, Hit, Node};+use craft_ui::docking::{DockArea, Hit, Node, Side};use egui::{Event, Modifiers, PointerButton, vec2};use egui_kittest::{Harness, kittest::Queryable};use lightcraft_ui_egui::{LightcraftApp, Services, UiState, docking::Panel, state::RightPanel};@@ -100,42 +100,45 @@ fn dragging_a_group_by_its_bar_moves_the_whole_group() {.expect("the Tools and Presets group draws its drag bar");let target = h.get_by_role_and_label(egui::accesskit::Role::Tab, "Library").rect().center();drag(&mut h, bar.center(), target);+ let mut library = start_dock(&h).into_iter().flatten().find(|panels| panels.contains(&Panel::Library)).unwrap();+ library.sort_by_key(|panel| panel.id());+ assert_eq!(library, [Panel::Library, Panel::Presets, Panel::Tools], "both panels of the dragged group joined Library");+ assert_eq!(h.state().ui.right, RightPanel::Edit);+}++/// The start dock's columns from the window edge inwards, each as its groups' panels.+fn start_dock(h: &Harness<'_, LightcraftApp>) -> Vec<Vec<Vec<Panel>>> {let layout = &h.state().ui.docking.as_ref().unwrap().layout;let mut nodes: Vec<_> = layout.root.iter().collect();- let mut groups = Vec::new();while let Some(node) = nodes.pop() {match node {Node::Split { first, second, .. } => nodes.extend([&**first, &**second]),- Node::Tabs { panels, .. } => groups.push(panels.clone()),+ Node::Dock { side: Side::Start, columns } => {+ return columns.iter().map(|column| column.groups.iter().map(|group| group.panels.clone()).collect()).collect();+ }_ => {}}}- let mut library = groups.into_iter().find(|panels| panels.contains(&Panel::Library)).unwrap();- library.sort_by_key(|panel| panel.id());- assert_eq!(library, [Panel::Library, Panel::Presets, Panel::Tools], "both panels of the dragged group joined Library");- assert_eq!(h.state().ui.right, RightPanel::Edit);+ Vec::new()}-/// LightCraft's side panels live in frames; a drop at the window's edge makes no dock column.+/// In a dock column, a group's top third stacks above it, its photo-side third adds a column+/// there and its middle joins its tabs.#[test]-fn an_edge_drop_does_not_create_a_dock() {- for at_right in [false, true] {+fn a_tab_dropped_on_a_dock_group_stacks_adds_a_column_or_joins_by_where_it_lands() {+ let cases: [(fn(egui::Rect) -> egui::Pos2, Vec<Vec<Vec<Panel>>>); 3] = [+ (|r| egui::pos2(r.center().x, r.top() + r.height() / 6.0), vec![vec![vec![Panel::Tools], vec![Panel::Library]]]),+ (|r| egui::pos2(r.right() - r.width() / 6.0, r.center().y), vec![vec![vec![Panel::Library]], vec![vec![Panel::Tools]]]),+ (|r| r.center(), vec![vec![vec![Panel::Library, Panel::Tools]]]),+ ];+ for (at, expected) in cases {let mut h = harness(None, 1400.0, 1.0);let library = h.state().widgets.iter().find(|(id, _)| id == "panel:left_panel").unwrap().1;- let tools = h.state().widgets.iter().find(|(id, _)| id == "panel:right_panel").unwrap().1;- let x = if at_right { tools.right() - 4.0 } else { library.left() + 4.0 };let source = h.get_by_role_and_label(egui::accesskit::Role::Tab, "Tools").rect().center();- drag(&mut h, source, egui::pos2(x, 500.0));- let layout = &h.state().ui.docking.as_ref().unwrap().layout;- assert!(layout.contains(&Panel::Tools));- let mut nodes: Vec<_> = layout.root.iter().collect();- while let Some(node) = nodes.pop() {- match node {- Node::Split { first, second, .. } => nodes.extend([&**first, &**second]),- Node::Dock { .. } => panic!("a drop at x = {x} made a dock: {layout:?}"),- _ => {}- }- }+ drag(&mut h, source, at(library));+ assert_eq!(start_dock(&h), expected, "dropped at {:?} of {library:?}", at(library));+ lightcraft_ui_egui::docking::validate(h.state().ui.docking.as_ref().unwrap()).unwrap();+ assert_eq!(h.state().ui.right, RightPanel::Edit);}}