Dock column: the last open group fills; groups asking for a fill no longer share

This commit is contained in:
aiongg
2026-11-16 15:52:27 +00:00
parent 63a4811416
commit dbeb743fab
3 changed files with 19 additions and 21 deletions
@@ -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<DockHeights>,
}
@@ -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<f32> {
let saved = |group: &GroupSize| group.saved.filter(|height| height.is_finite());
let open: Vec<usize> = (0..groups.len()).filter(|at| groups.get(*at).is_some_and(|group| !group.minimized)).collect();
let unsaved =
|at: &usize, test: fn(Option<DockHeights>) -> bool| groups.get(*at).is_some_and(|group| saved(group).is_none() && test(group.content));
let mut shared: Vec<usize> = 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<usize> = 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<usize> = open.iter().copied().filter(|at| !shared.contains(at)).collect();
let mut defaulted: Vec<usize> = sized.iter().copied().filter(|at| groups.get(*at).is_some_and(|group| saved(group).is_none())).collect();
let mut heights: Vec<f32> = groups
+5 -5
View File
@@ -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<DockHeights>,
/// 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.
+1
View File
@@ -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.