From dbeb743fabb4c00574f829645f415ef67a3d7ad5 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 15:52:27 +0000 Subject: [PATCH] Dock column: the last open group fills; groups asking for a fill no longer share --- .../src/docking/dock_column/sizing.rs | 29 +++++++++---------- crates/ui-panels/src/docking/spec.rs | 10 +++---- docs/ui-docking.md | 1 + 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/crates/ui-panels/src/docking/dock_column/sizing.rs b/crates/ui-panels/src/docking/dock_column/sizing.rs index 4d431cd19..868ed67ae 100644 --- a/crates/ui-panels/src/docking/dock_column/sizing.rs +++ b/crates/ui-panels/src/docking/dock_column/sizing.rs @@ -66,7 +66,7 @@ pub struct GroupSize { /// The least height. pub min: f32, /// The heights the panels ask for, with the strip added to `fill` only when it is above 0, so 0 still means the - /// group does not ask to fill. + /// group asks for no more than its minimum when it fills the column. pub content: Option, } @@ -77,24 +77,21 @@ impl GroupSize { } } -/// The heights of stacked groups in a column body `room` high. Minimized groups take `strip`, groups with a saved -/// height keep it, and the groups the user never resized whose content asks to fill share what is left. Without -/// those, the groups without content heights share it, and when every open group has a height the last one takes -/// the rest. Other groups take their default height, or their minimum. Default heights shrink towards their compact -/// heights until the filling groups get their fill height, nearest the filling groups first; then every height -/// shrinks in proportion towards its minimum. +/// The heights of stacked groups in a column body `room` high. The column's last open group fills it: it takes what +/// is left, and asks for its fill height (its minimum when its fill is 0). Groups the user never resized that ask +/// for no heights share what is left with it. Minimized groups take `strip`, other groups with a saved height keep +/// it, and the rest take their default height. Default heights shrink towards their compact heights until the +/// filling groups get their fill height, nearest the filling groups first; then every height shrinks in proportion +/// towards its minimum. pub fn group_heights(groups: &[GroupSize], strip: f32, room: f32) -> Vec { let saved = |group: &GroupSize| group.saved.filter(|height| height.is_finite()); let open: Vec = (0..groups.len()).filter(|at| groups.get(*at).is_some_and(|group| !group.minimized)).collect(); - let unsaved = - |at: &usize, test: fn(Option) -> bool| groups.get(*at).is_some_and(|group| saved(group).is_none() && test(group.content)); - let mut shared: Vec = open.iter().copied().filter(|at| unsaved(at, |content| content.is_some_and(|content| content.fill > 0.0))).collect(); - if shared.is_empty() { - shared = open.iter().copied().filter(|at| unsaved(at, |content| content.is_none())).collect(); - } - if shared.is_empty() { - shared.extend(open.last()); - } + let last = open.last().copied(); + let shared: Vec = open + .iter() + .copied() + .filter(|at| Some(*at) == last || groups.get(*at).is_some_and(|group| saved(group).is_none() && group.content.is_none())) + .collect(); let sized: Vec = open.iter().copied().filter(|at| !shared.contains(at)).collect(); let mut defaulted: Vec = sized.iter().copied().filter(|at| groups.get(*at).is_some_and(|group| saved(group).is_none())).collect(); let mut heights: Vec = groups diff --git a/crates/ui-panels/src/docking/spec.rs b/crates/ui-panels/src/docking/spec.rs index 451ab69ed..a888703a7 100644 --- a/crates/ui-panels/src/docking/spec.rs +++ b/crates/ui-panels/src/docking/spec.rs @@ -7,7 +7,8 @@ use craft_host::target::WindowKind; use egui::Vec2; /// Body heights a panel asks for in a dock column while the user has not resized its group. Like [`SizeLimits`] -/// they exclude the tab strip, and a group takes the largest of each among its panels. +/// they exclude the tab strip, and a group takes the largest of each among its panels. The dock picks the group that +/// fills a column: its last open group. #[derive(Clone, Copy, Debug, PartialEq)] #[non_exhaustive] pub struct DockHeights { @@ -15,8 +16,8 @@ pub struct DockHeights { pub default: f32, /// The height it gives way down to, so the group that fills the column keeps its `fill`. pub compact: f32, - /// The height it asks for when it fills the column: groups at their default shrink towards `compact` before it - /// gets less. + /// The height it asks for when it is the column's last open group, which fills the column: groups at their + /// default shrink towards `compact` before it gets less. pub fill: f32, } @@ -60,8 +61,7 @@ pub struct PanelSpec { /// Body size limits. pub limits: SizeLimits, /// How the panel's group sizes itself in a dock column until the user resizes it. `None` shares the column's - /// free height with the other groups that have none when no group asks for a fill, and takes the group's - /// minimum when one does. + /// free height with the column's last open group, which fills it, and with the other groups that have none. pub heights: Option, /// The size the panel floats at: its width and the most height it takes. `None`: the size of the group it floats /// out of, else `FloatSpace`'s default size. diff --git a/docs/ui-docking.md b/docs/ui-docking.md index c0a0cae2c..bfcf59803 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -98,6 +98,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords - A tab drag carries a `PanelDrag`; a group or column drag carries a `GroupDrag`. Groups and columns register `DockSpot`s in `DockTargets`, and `resolve_drop` maps the spot under the pointer to an `Action`. - Ctrl or Cmd held at the release floats the drop. A release over the dragged unit's own group leaves it where it is. - A drag ends without a change when another arrangement replaces the workspace it started on: it records the workspace's revision, which `Workspace::replace` and the `WorkspaceSet` switch and reset change. The dock's own edits keep the revision, so they keep the drag. +- A dock column's last open group fills the column: it takes the height the other groups leave and asks for its `DockHeights::fill`. The other groups keep the height the user gave them, or take their `DockHeights::default`, which shrinks towards `compact` before the filling group gets less than its fill. Groups that ask for no heights share the free height with the filling group. - Split handles are Tab stops, and the arrow keys move them. A divider drag is one gesture in `DockAreaOutput::edit`. - A panel command (`DockCommands`) acts on the shown panel of the group that takes it. A menu row, a key and the command palette run the same code: `actions` turns the command into `Action`s.