diff --git a/crates/ui-egui/src/panels/dock.rs b/crates/ui-egui/src/panels/dock.rs index 267125d603..0dc8c14a3a 100644 --- a/crates/ui-egui/src/panels/dock.rs +++ b/crates/ui-egui/src/panels/dock.rs @@ -73,7 +73,7 @@ pub fn dock_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // An iconic-only dock keeps its narrow displayed width instead of being raised to the expanded // minimum; other docks keep the usual minimum and maximum. let iconic = metrics.iconic_only; - let min_visible = if iconic { 1.0 } else { min_dock }; + let min_visible = if iconic { crate::panel_docking::ICONIC_WIDTH } else { min_dock }; let mut stored = if iconic { metrics.width.clamp(1.0, max_dock) } else { metrics.width.clamp(min_dock, max_dock) }; let drag_id = egui::Id::unique("dock-edge-drag"); // Resizing is unavailable while locked, modal, or when the parent UI is disabled (screen @@ -169,9 +169,7 @@ pub fn dock_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let color = if active { t.accent } else { t.separator }; ui.ctx().layer_painter(line).vline(panel_edge, panel_rect.y_range(), Stroke::new(1.0, color)); if response.drag_started() { - // The press origin, not the threshold-crossing frame: the dock then tracks the - // pointer exactly from where the user pressed. - let start_x = ui.ctx().input(|i| i.pointer.press_origin()).map_or(panel_edge, |pos| pos.x); + let start_x = response.interact_pointer_pos().map_or(panel_edge, |pos| pos.x); ui.ctx().data_mut(|d| d.insert_temp(drag_id, (start_x, panel_w))); } if response.dragged() { diff --git a/crates/ui-egui/src/panels/panel_docking.rs b/crates/ui-egui/src/panels/panel_docking.rs index 09a70e33ad..5777da8357 100644 --- a/crates/ui-egui/src/panels/panel_docking.rs +++ b/crates/ui-egui/src/panels/panel_docking.rs @@ -137,9 +137,14 @@ pub(crate) fn dock_is_empty(app: &PhotocraftApp) -> bool { dock_metrics(app).empty } -/// A column's width as craft-ui displays it: `iconic_width` while collapsed to icons. +/// craft-ui's iconic column width without a saved width, and its renderer's clamp. +pub(crate) const ICONIC_WIDTH: f32 = 36.0; +const ICONIC_MAX_WIDTH: f32 = 240.0; + +/// A column's width as craft-ui draws it: `iconic_width` (default 36, clamped to 36..240) while +/// collapsed to icons, else the expanded width. fn display_width(column: &Column) -> f32 { - if column.iconic { column.iconic_width.unwrap_or(column.width) } else { column.width } + if column.iconic { column.iconic_width.unwrap_or(ICONIC_WIDTH).clamp(ICONIC_WIDTH, ICONIC_MAX_WIDTH) } else { column.width } } /// The least displayed width of a column: the app's 220-point panel minimum, unless the column is @@ -147,7 +152,13 @@ fn display_width(column: &Column) -> f32 { const MIN_COLUMN_WIDTH: f32 = 220.0; fn column_minimum(column: &Column) -> f32 { - if column.iconic || column.groups.iter().all(|group| group.panels.is_empty()) { 1.0 } else { MIN_COLUMN_WIDTH } + if column.iconic { + ICONIC_WIDTH + } else if column.groups.iter().all(|group| group.panels.is_empty()) { + 1.0 + } else { + MIN_COLUMN_WIDTH + } } fn columns_minimum(columns: &[Column]) -> f32 { @@ -159,7 +170,7 @@ fn columns_minimum(columns: &[Column]) -> f32 { fn set_display_width(column: &mut Column, width: f32) { let width = width.max(1.0); if column.iconic { - column.iconic_width = Some(width); + column.iconic_width = Some(width.clamp(ICONIC_WIDTH, ICONIC_MAX_WIDTH)); } else { column.width = width; } diff --git a/crates/ui-egui/src/panels/panel_docking/tests.rs b/crates/ui-egui/src/panels/panel_docking/tests.rs index ad4e1a5592..af6ec353fb 100644 --- a/crates/ui-egui/src/panels/panel_docking/tests.rs +++ b/crates/ui-egui/src/panels/panel_docking/tests.rs @@ -1476,10 +1476,45 @@ fn an_iconic_dock_column_takes_its_iconic_width() { assert!((dock_width(&app) - expanded).abs() < 0.5, "expanding restores the expanded width, got {} (was {expanded})", dock_width(&app)); } -/// An iconic-only dock keeps its narrow panel instead of reserving the expanded minimum; the rest -/// of the window stays with the canvas. +/// Collapsing a column through craft-ui's action leaves `iconic_width` unset; the dock must use +/// the renderer's 36-point default rather than the expanded width. #[test] fn an_iconic_only_dock_keeps_its_narrow_panel() { + let mut app = app(); + let layout = legacy(&app); + let panel = { + let root = layout.root.as_ref().expect("the legacy layout has a root"); + let dock = match root { + Node::Split { second, .. } => second.as_ref(), + _ => root, + }; + let Node::Dock { columns, .. } = dock else { panic!("the end dock is missing") }; + columns[0].groups[0].panels[0].clone() + }; + let mut workspace = Workspace::new(layout); + workspace.apply(Action::SetIconic { panel, iconic: true }, permissions).expect("the column collapses"); + { + let root = workspace.layout.root.as_ref().expect("root"); + let dock = match root { + Node::Split { second, .. } => second.as_ref(), + _ => root, + }; + let Node::Dock { columns, .. } = dock else { panic!("the end dock is missing") }; + assert!(columns[0].iconic); + assert!(columns[0].iconic_width.is_none(), "the collapse action leaves the stored width unset"); + } + app.ui.docking = Some(workspace); + assert!((dock_width(&app) - 36.0).abs() < 0.5, "an unset iconic width displays 36 points, got {}", dock_width(&app)); + let h = dock_panel_harness(app, vec2(1280.0, 800.0), crate::theme::ThemeKind::ProMedium); + let rail = if h.state().ui.panels.rail { 36.0 } else { 0.0 }; + let drawn = crate::panels::dock_panel_width(&h.ctx); + assert!((drawn - (36.0 + rail)).abs() < 2.0, "the iconic panel is its 36 points plus the rail ({rail}), got {drawn}"); + assert!(drawn < 120.0, "the iconic panel must not take the expanded minimum, got {drawn}"); +} + +/// Stored iconic widths are clamped to the renderer's 36..240 bounds. +#[test] +fn iconic_widths_follow_the_renderer_clamp() { let mut app = app(); let mut layout = legacy(&app); { @@ -1490,14 +1525,18 @@ fn an_iconic_only_dock_keeps_its_narrow_panel() { }; let Node::Dock { columns, .. } = dock else { panic!("the end dock is missing") }; columns[0].iconic = true; - columns[0].iconic_width = Some(36.0); + columns[0].iconic_width = Some(500.0); } app.ui.docking = Some(Workspace::new(layout)); - let h = dock_panel_harness(app, vec2(1280.0, 800.0), crate::theme::ThemeKind::ProMedium); - let rail = if h.state().ui.panels.rail { 36.0 } else { 0.0 }; - let panel = crate::panels::dock_panel_width(&h.ctx); - assert!((panel - (36.0 + rail)).abs() < 2.0, "the iconic panel is its 36 points plus the rail ({rail}), got {panel}"); - assert!(panel < 120.0, "the iconic panel must not take the expanded minimum, got {panel}"); + assert!((dock_width(&app) - 240.0).abs() < 0.5, "a stored 500 displays at most 240, got {}", dock_width(&app)); + let root = app.ui.docking.as_mut().unwrap().layout.root.as_mut().unwrap(); + let dock = match root { + Node::Split { second, .. } => second.as_mut(), + _ => root, + }; + let Node::Dock { columns, .. } = dock else { panic!("the end dock is missing") }; + columns[0].iconic_width = Some(10.0); + assert!((dock_width(&app) - 36.0).abs() < 0.5, "a stored 10 displays at least 36, got {}", dock_width(&app)); } /// Closing every panel leaves the dock with nothing in it, which the dock-edge layout uses to /// take no width for the column.