mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Toolbar side: bound the dock-edge layout, enforce panel minima, match iconic widths
- The dock-edge panel leaves the toolbar and the 200-point canvas minimum room, so a narrow window shrinks the dock instead of the canvas. - The empty dock runs the docking pass in a child ui that does not consume the parent layout, so the toolbar and canvas keep their space. - Column scaling allocates each column's 220-point panel minimum first and shares the rest proportionally; requests below the sum of minima stop there. - Iconic columns use craft-ui's renderer rule: iconic_width.unwrap_or(36).clamp(36, 240), including the real collapse case that leaves iconic_width unset. - Dock metrics come from one layout snapshot per frame; dead empty-dock branches are gone; the content-edge interceptor is one point either side; the toolbar target comment is corrected and the Side::End assumption documented. - Tests: narrow-window canvas minimum, empty dock composed with toolbar/canvas, minimum-aware two-column widths, collapse via Action::SetIconic leaving iconic_width unset, and the 36..240 clamp. The press-origin change was reverted: Sense::drag starts immediately.
This commit is contained in:
1 parent
9fbca8fdaa
commit
9f4e559919
3 files changed
+64
-16
No files matched your search
@@ -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() {
|
||||
|
||||
@@ -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<String>) -> 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<String>) -> f32 {
|
||||
const MIN_COLUMN_WIDTH: f32 = 220.0;
|
||||
|
||||
fn column_minimum(column: &Column<String>) -> 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<String>]) -> f32 {
|
||||
@@ -159,7 +170,7 @@ fn columns_minimum(columns: &[Column<String>]) -> f32 {
|
||||
fn set_display_width(column: &mut Column<String>, 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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user