diff --git a/crates/ui/src/docking/dock_model.rs b/crates/ui/src/docking/dock_model.rs index 27390e092..37c6fa074 100644 --- a/crates/ui/src/docking/dock_model.rs +++ b/crates/ui/src/docking/dock_model.rs @@ -326,6 +326,35 @@ pub(super) fn split_frame
(root: &mut Node
, path: &[bool], new: Node
, zo true } +/// [`split_frame`] with the sizes of [`Placement::SplitSized`]: the new split takes `size`, and +/// the nearest enclosing split whose divider runs along the frame's `zone` side takes `outer`. +/// False when there is no such split, or a dock is beyond it. +pub(super) fn split_frame_sized
(root: &mut Node
, path: &[bool], new: Node
, zone: Zone, size: SplitSize, outer: SplitSize) -> bool { + let axis = if matches!(zone, Zone::Top | Zone::Bottom) { SplitAxis::Vertical } else { SplitAxis::Horizontal }; + // A divider on the frame's start side (left or top) belongs to a split holding the frame + // in its second child. + let start = matches!(zone, Zone::Left | Zone::Top); + let enclosing = (0..path.len()).rev().find(|&depth| { + path.get(depth) == Some(&start) && matches!(node_at(root, &path[..depth]), Some(Node::Split { axis: own, .. }) if *own == axis) + }); + let Some(depth) = enclosing else { return false }; + let Some(Node::Split { size: own, first, second, .. }) = node_at_mut(root, &path[..depth]) else { return false }; + if zone == Zone::Center || matches!(**first, Node::Dock { .. }) || matches!(**second, Node::Dock { .. }) { + return false; + } + *own = outer; + if !split_frame(root, path, new, zone) { + return false; + } + match node_at_mut(root, path) { + Some(Node::Split { size: own, .. }) => { + *own = size; + true + } + _ => false, + } +} + /// Insert `new` at `index` and select the member at `index + selected`. fn splice
(panels: &mut Vec
, active: &mut usize, index: usize, new: Vec
, selected: usize) {
let index = index.min(panels.len());
@@ -799,6 +828,18 @@ impl {
let root = self.tree_mut(window).ok_or(DockError::MissingTarget)?;
if split_frame(root, path, new, zone) { Ok(()) } else { Err(DockError::MissingTarget) }
}
+ Placement::SplitSized { zone, size, outer } => {
+ let (window, path) = place.tree_path().ok_or(DockError::InvalidPlacement)?;
+ let new = match moving.node {
+ Some(node) => node,
+ None => {
+ let (panels, active) = flatten(moving.groups);
+ Node::Tabs { panels, active }
+ }
+ };
+ let root = self.tree_mut(window).ok_or(DockError::MissingTarget)?;
+ if split_frame_sized(root, path, new, zone, size, outer) { Ok(()) } else { Err(DockError::InvalidPlacement) }
+ }
// A floating window is a tree: a group above or below splits the anchor's group.
Placement::Group { below, .. } if matches!(place, Place::Floating { .. }) => {
let zone = if below { Zone::Bottom } else { Zone::Top };
diff --git a/crates/ui/src/docking/drop_tests.rs b/crates/ui/src/docking/drop_tests.rs
index 0098aeb58..87de29b3c 100644
--- a/crates/ui/src/docking/drop_tests.rs
+++ b/crates/ui/src/docking/drop_tests.rs
@@ -432,3 +432,25 @@ fn a_header_drag_in_a_window_of_two_groups_still_offers_the_other_group() {
out.actions
);
}
+
+#[test]
+fn a_drop_beside_a_frame_too_narrow_to_halve_takes_room_from_its_neighbour() {
+ // Frame 2 is 60 pt wide beside frame 1; group 4 floats over frame 1.
+ let root =
+ Node::Split { axis: SplitAxis::Horizontal, size: SplitSize::FixedSecond(60.0), first: Box::new(tabs(&[1])), second: Box::new(tabs(&[2])) };
+ let layout = Layout { root: Some(root), floating: vec![Floating::single(vec![4], 0, [100.0, 100.0, 200.0, 200.0])] };
+ let mut d = DockDriver::new(layout, Bodies::default());
+ let (body, rect) = group(&d, 2);
+ let at = pos2(body.left() + 8.0, body.center().y);
+ d.hold(tab(&d, 4), at);
+ assert!(d.filled(line(rect, Zone::Left)), "a line along frame 2's left edge");
+ let out = d.release(at);
+ assert!(
+ matches!(&out.actions[..], [Action::Move { panel: 4, anchor: 2, placement: Placement::SplitSized { zone: Zone::Left, .. } }]),
+ "{:?}",
+ out.actions
+ );
+ d.settle();
+ assert!((group(&d, 2).1.width() - rect.width()).abs() < 1.0, "frame 2 keeps its width");
+ assert!(group(&d, 4).1.width() >= 40.0);
+}
diff --git a/crates/ui/src/docking/model.rs b/crates/ui/src/docking/model.rs
index 6bbf15ad2..31dcfcfa0 100644
--- a/crates/ui/src/docking/model.rs
+++ b/crates/ui/src/docking/model.rs
@@ -1,7 +1,8 @@
use std::{collections::HashSet, fmt, hash::Hash};
use super::dock_model::{
- Column, ColumnLocation, Group, GroupLocation, Moving, PanelState, Place, Side, Target, Unit, node_at, split_frame, tree_panels, valid_column,
+ Column, ColumnLocation, Group, GroupLocation, Moving, PanelState, Place, Side, Target, Unit, node_at, split_frame, split_frame_sized,
+ tree_panels, valid_column,
};
use crate::layout::{SplitAxis, SplitSize};
@@ -305,6 +306,13 @@ pub enum Placement {
/// Center inserts after the anchor; sides split the anchor's frame into two halves, and
/// every other frame keeps its size. Sides apply to `Tabs` and `Stack` nodes only.
Split(Zone),
+ /// A side [`Placement::Split`] that gives the new frame its own room instead of half the
+ /// anchor's frame: the new split takes `size`, and `outer` replaces the size of the nearest
+ /// enclosing split whose divider runs along the anchor frame's `zone` side, so the frames
+ /// beyond that divider give the room. The renderer offers it beside a frame too small to
+ /// halve. `Center`, and an anchor without such a divider or with a dock beyond it, are
+ /// invalid.
+ SplitSized { zone: Zone, size: SplitSize, outer: SplitSize },
/// A new group above or below the anchor's group in a dock column. On an anchor in a
/// floating window, a split of the anchor's group above or below.
/// `height` is the inserted group's preferred height ([`super::Group::height`]); `None`
@@ -1309,6 +1317,10 @@ impl {
let new = Node::Tabs { panels: vec![entry.panel], active: 0 };
return if split_frame(root, &path, new, zone) { Ok(()) } else { Err(DockError::MissingTarget) };
}
+ if let Placement::SplitSized { zone, size, outer } = placement {
+ let new = Node::Tabs { panels: vec![entry.panel], active: 0 };
+ return if split_frame_sized(root, &path, new, zone, size, outer) { Ok(()) } else { Err(DockError::InvalidPlacement) };
+ }
if insert_node(root, &entry, anchor, &placement) { Ok(()) } else { Err(DockError::MissingTarget) }
}
}
@@ -1318,7 +1330,7 @@ impl {
fn placement_allowed (placement: &Placement , anchor: Permissions) -> bool {
match placement {
Placement::Tab { .. } | Placement::Split(Zone::Center) => anchor.accepts_tabs,
- Placement::Split(_) => anchor.accepts_splits,
+ Placement::Split(_) | Placement::SplitSized { .. } => anchor.accepts_splits,
_ => true,
}
}
diff --git a/crates/ui/src/docking/model_tests.rs b/crates/ui/src/docking/model_tests.rs
index 9327fd4d3..d510939bd 100644
--- a/crates/ui/src/docking/model_tests.rs
+++ b/crates/ui/src/docking/model_tests.rs
@@ -754,3 +754,23 @@ fn edge_placement_splits_the_part_between_the_docks_or_the_root() {
assert_eq!(frames.apply(Action::Move { panel: 2, anchor: 1, placement: Placement::Edge(Zone::Center) }), Err(DockError::InvalidPlacement));
assert_eq!(frames, before);
}
+
+#[test]
+fn a_sized_split_sets_the_new_split_and_the_enclosing_one_beside_the_anchor() {
+ // 1 | (2 | 3): 4 goes left of 3, and the split between 2 and 3 gives the room.
+ let layout = Layout {
+ root: Some(hsplit(SplitSize::Ratio(0.5), tabs(&[1], 0), hsplit(SplitSize::FixedSecond(60.0), tabs(&[2], 0), tabs(&[3], 0)))),
+ floating: vec![Floating::single(vec![4], 0, [0.0, 0.0, 100.0, 100.0])],
+ };
+ let sized = |zone| Placement::SplitSized { zone, size: SplitSize::FixedFirst(100.0), outer: SplitSize::FixedSecond(164.0) };
+ let mut moved = layout.clone();
+ moved.apply(Action::Move { panel: 4, anchor: 3, placement: sized(Zone::Left) }).unwrap();
+ let inner = hsplit(SplitSize::FixedSecond(164.0), tabs(&[2], 0), hsplit(SplitSize::FixedFirst(100.0), tabs(&[4], 0), tabs(&[3], 0)));
+ assert_eq!(moved.root, Some(hsplit(SplitSize::Ratio(0.5), tabs(&[1], 0), inner)));
+ // 1 has no divider on its left, and a center is no side.
+ for (anchor, zone) in [(1, Zone::Left), (3, Zone::Center)] {
+ let mut moved = layout.clone();
+ assert_eq!(moved.apply(Action::Move { panel: 4, anchor, placement: sized(zone) }), Err(DockError::InvalidPlacement), "{anchor} {zone:?}");
+ assert_eq!(moved, layout);
+ }
+}
diff --git a/crates/ui/src/docking/render/preview.rs b/crates/ui/src/docking/render/preview.rs
index 75b9365f2..740665c21 100644
--- a/crates/ui/src/docking/render/preview.rs
+++ b/crates/ui/src/docking/render/preview.rs
@@ -10,7 +10,7 @@ use crate::docking::{
surface::TAB_PADDING,
targets::{SIDE_EDGE_ZONE_DEPTH, resolve_drop_on},
};
-use crate::layout::SplitAxis;
+use crate::layout::{SplitAxis, SplitSize};
/// Ctrl (Windows, Linux) or Cmd (macOS) held: the drop floats and no target is offered.
fn float_only(ctx: &Context) -> bool {
@@ -182,7 +182,7 @@ impl , action: &impl Fn(Target ) -> Action ) -> Option ) -> Vec<(&'l Node , Rect)> {
+ let sizer = self.sizer();
+ let mut out = Vec::new();
+ for (root, area) in self.trees(layout) {
+ let mut drawn = Vec::new();
+ sizer.groups(root, area, &mut drawn);
+ out.extend(drawn.into_iter().map(|d| (d.node, d.rect)));
+ }
+ out
+ }
+
/// `proposal`, marked a no-op when `action` at it would leave every panel where it is,
/// changing only sizes ([`Layout::same_arrangement`]): a lone group dropped beside the
/// group it already borders, or a tab on the edge its frame already holds. Such a drop
@@ -345,7 +427,7 @@ impl , filled: bool) {
if crate::docking::targets::usable(proposal.preview) {
- let beside = matches!(proposal.placement, Placement::Split(zone) | Placement::Edge(zone) if zone != Zone::Center);
+ let beside = matches!(proposal.placement, Placement::Split(zone) | Placement::SplitSized { zone, .. } | Placement::Edge(zone) if zone != Zone::Center);
if self.style.side_edge_zones {
drop_preview(painter, proposal.preview.shrink(1.0), self.style.accent, filled);
} else if beside {
@@ -551,7 +633,7 @@ impl | match proposal.placement {
_ if proposal.noop => None,
- Placement::Split(zone) => Some(zone),
+ Placement::Split(zone) | Placement::SplitSized { zone, .. } => Some(zone),
Placement::Tab { .. } => Some(Zone::Center),
_ => None,
};
@@ -715,6 +797,15 @@ impl , panel: &P) -> bool {
+ match node {
+ Node::Tabs { panels, .. } => panels.contains(panel),
+ Node::Stack { entries } => entries.iter().any(|e| &e.panel == panel),
+ Node::Split { .. } | Node::Dock { .. } => false,
+ }
+}
+
/// The panel that names a drawn group: its first panel; none for a dock or a split.
fn lead (node: &Node ) -> Option<&P> {
match node {
diff --git a/crates/ui/src/docking/render/sizes.rs b/crates/ui/src/docking/render/sizes.rs
index b1c9fd493..415ecf8dc 100644
--- a/crates/ui/src/docking/render/sizes.rs
+++ b/crates/ui/src/docking/render/sizes.rs
@@ -312,16 +312,22 @@ impl Sizer<'_, P> {
/// The size of a split at `path` whose first child is `first` of `available` points, in the
/// split's own mode `size`: a fixed side keeps its points, a ratio stays a ratio.
fn push_size(path: &[bool], size: SplitSize, first: f32, available: f32, out: &mut Vec<(Vec , location: &Location , panel:
Placement::Split(Zone::Bottom) => (Placement::Split(Zone::Top), location.size),
Placement::Group { below, .. } => (Placement::Group { below: !below, height: None }, None),
Placement::Column { after } => (Placement::Column { after: !after }, None),
+ Placement::SplitSized { zone, .. } => match zone {
+ Zone::Left => (Placement::Split(Zone::Right), location.size),
+ Zone::Right => (Placement::Split(Zone::Left), location.size),
+ Zone::Top => (Placement::Split(Zone::Bottom), location.size),
+ Zone::Bottom => (Placement::Split(Zone::Top), location.size),
+ Zone::Center => return None,
+ },
Placement::Edge(_) => return None,
};
Some(Location { floating: None, anchor: Some(panel.clone()), placement, size, sibling: Vec::new(), ..hidden.clone() })
diff --git a/docs/ui-docking.md b/docs/ui-docking.md
index 4ad822a4b..79415dd61 100644
--- a/docs/ui-docking.md
+++ b/docs/ui-docking.md
@@ -85,7 +85,9 @@ layout.apply(Action::Move {
that side or a new group above or below in a dock. A floating window takes splits as the
docked layout does; `Placement::Group` on a floating anchor splits its group above or below.
- A side split zone puts what moves in a new half-size split of the anchor's frame, and no
- other frame changes size. The new split has its own divider.
+ other frame changes size. The new split has its own divider. `Placement::SplitSized` sizes
+ that split instead (`size`) and resizes the enclosing split whose divider runs along the
+ anchor frame's side (`outer`), so the frames beyond that divider give the new frame its room.
- Other actions select, minimize, collapse to icons, resize splits (`ResizeSplit` in the docked
layout, `ResizeWindowSplit` in the floating window holding a panel), columns and groups, and
move a floating window to its own OS window (`SetNative`, and `SetMonitor` for the monitor it
@@ -242,8 +244,11 @@ A flyout fits its content the same way, without the title bar.
- Beside a frame is a split of that frame. Beside a group in a dock column, the top and bottom
stack a new group above or below it, and the left and right make a new column on that side.
- A frame too narrow or short for two halves of `DockStyle::min_pane` still splits when the
- frames beyond it can give the room, as they do for a dragged divider. When they cannot, that
- side joins the frame's tabs instead, or takes nothing when the frame takes no tabs. The gap
+ frames beyond it can give the room, as they do for a dragged divider. When they cannot, the
+ frame keeps its size and the new frame takes the width (or height) the moved panels have now,
+ at least its minimum, from the frames beyond the frame's divider on that side
+ (`Placement::SplitSized`). When those have no room either, that side joins the frame's tabs
+ instead, or takes nothing when the frame takes no tabs. The gap
between two frames is no target.
- Bands along borders come before the group zones. Each is centred on its border where the
pointer can reach both sides: