diff --git a/crates/behavior/src/dock/action.rs b/crates/behavior/src/dock/action.rs index eb862807a..8075b7bf4 100644 --- a/crates/behavior/src/dock/action.rs +++ b/crates/behavior/src/dock/action.rs @@ -6,7 +6,7 @@ use crate::placement::Placement; use super::{ DockSide, - groups::{GroupLocation, Target}, + groups::{DockEdge, GroupLocation, Target}, policy::Permissions, split::SplitSize, }; @@ -22,7 +22,7 @@ pub enum DockPlacement
{ before: Option
, }, /// 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. + /// every other frame keeps its size. Sides apply to `Tabs` and `Stack` nodes of the docked tree only. Split(DockSide), /// A side [`DockPlacement::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 @@ -40,8 +40,7 @@ pub enum DockPlacement
{ /// New size of the enclosing split that gives up the room. 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. + /// A new group above or below the anchor's group in its column, docked or floating. /// `height` is the inserted group's preferred height (`Group::height`); `None` /// keeps a moved group's own height, or shares the free height for a new group. #[non_exhaustive] @@ -52,7 +51,8 @@ pub enum DockPlacement
{
#[serde(default, skip_serializing_if = "Option::is_none")]
height: Option {
/// rather than accidentally inserting beside only its first leaf when restoring.
#[serde(default)]
pub sibling: Vec ,
- /// Group and column state when the panel was in a dock. Applies when
- /// restoring creates a new group, column or dock for the panel.
+ /// Group and column state when the panel was in a column, docked or floating. Applies when
+ /// restoring creates a new group, column, dock or window for the panel.
#[serde(default)]
pub group: Option {
/// The window rect in logical points. Saved as `[x, y, width, height]`.
#[serde(with = "crate::dock::rect_serde")]
rect: Rect,
+ /// The window's [`Floating::edge`](super::Floating::edge): the edge the area decided from where a collapsed
+ /// window's strip was dropped. `None` (any move of an expanded window, and a sender without the float area)
+ /// leaves the edge to the area, nearer `rect`.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ edge: Option {
/// The new size.
size: SplitSize,
},
- /// [`Action::ResizeSplit`] in the floating window holding `panel`, with a path from its
- /// root.
- #[non_exhaustive]
- ResizeWindowSplit {
- /// The panel the action applies to.
- panel: P,
- /// Path from the root: false is the first child, true the second.
- path: Vec {
/// Moves towards the start; false moves towards the end.
up: bool,
},
- /// Move the dock column containing `panel`. `Float` makes a window of its groups.
+ /// Move the column containing `panel`, docked or a floating window's, with its state. `Float` makes a window of
+ /// it.
#[non_exhaustive]
MoveColumn {
/// The panel the action applies to.
@@ -252,16 +247,17 @@ pub enum Action {
/// The panel the action applies to.
panel: P,
},
- /// Minimize a dock group to its tab strip, or the floating window holding the panel to its
- /// title bar (and the strip of its only group). On an accordion entry, closes it.
+ /// Minimize the panel's group to its tab strip, docked or floating. On an accordion entry, closes it.
#[non_exhaustive]
SetMinimized {
/// The panel the action applies to.
panel: P,
- /// Only the title bar or tab strip shows.
+ /// Only the tab strip shows.
minimized: bool,
},
- /// Collapse the panel's dock column to icons, or expand it.
+ /// Collapse the panel's column to icons, or expand it, docked or floating. Refused
+ /// ([`DockError::NotAllowed`](super::DockError::NotAllowed)) for a column holding a panel that does not
+ /// collapse ([`Permissions::collapses`]).
#[non_exhaustive]
SetIconic {
/// The panel the action applies to.
@@ -269,7 +265,9 @@ pub enum Action {
/// Collapses the column to an icon strip.
iconic: bool,
},
- /// Set the expanded width in points of the panel's dock column.
+ /// Set the expanded width in points of the panel's column; a floating window's rect takes it. Refused
+ /// ([`DockError::InvalidPlacement`](super::DockError::InvalidPlacement)) for a stepped column
+ /// ([`Column::steps`](super::Column::steps)).
#[non_exhaustive]
ResizeColumn {
/// The panel the action applies to.
@@ -277,6 +275,15 @@ pub enum Action {
/// Width in points.
width: f32,
},
+ /// Set the width of the panel's column, docked or floating, to `steps` of its panel's content columns
+ /// ([`Column::steps`](super::Column::steps)). At least 1.
+ #[non_exhaustive]
+ SetColumnSteps {
+ /// The panel the action applies to.
+ panel: P,
+ /// Content columns.
+ steps: u16,
+ },
/// Preferred height of a dock group or of an accordion entry.
#[non_exhaustive]
ResizeGroup {
@@ -285,7 +292,7 @@ pub enum Action {
/// Preferred height in points; `None` shares the free height.
height: Option {
/// Width in points.
width: Option {
/// Offset in points; negative is above the icons.
offset: Option Action {
Self::OpenAt { panel, anchor, placement }
}
- /// Builds [`Action::MoveFloating`].
+ /// Builds [`Action::MoveFloating`] with no edge: the area takes the edge nearer `rect`.
pub fn move_floating(panel: P, rect: Rect) -> Self {
- Self::MoveFloating { panel, rect }
+ Self::MoveFloating { panel, rect, edge: None }
+ }
+
+ /// Builds [`Action::MoveFloating`] with the window's edge.
+ pub fn move_floating_with_edge(panel: P, rect: Rect, edge: Option Action {
Self::ResizeSplit { path, size }
}
- /// Builds [`Action::ResizeWindowSplit`].
- pub fn resize_window_split(panel: P, path: Vec Action {
Self::ResizeColumn { panel, width }
}
+ /// Builds [`Action::SetColumnSteps`].
+ pub fn set_column_steps(panel: P, steps: u16) -> Self {
+ Self::SetColumnSteps { panel, steps }
+ }
+
/// Builds [`Action::ResizeGroup`].
pub fn resize_group(panel: P, height: Option DockPlacement {
}
impl DockPlacement {
- /// Whether the anchor's permissions take this placement: tabs need `accepts_tabs`, side
- /// splits `accepts_splits`, and so does a group placed at an anchor in a floating window
- /// (`floating`), which splits the anchor's frame.
- pub fn allowed_by(&self, anchor: Permissions, floating: bool) -> bool {
+ /// Whether the anchor's permissions take this placement: tabs need `accepts_tabs` and `shares_column`, a group
+ /// in the anchor's column `shares_column`, and side splits `accepts_splits`. Whether the moving panels share a
+ /// column is the apply's own check.
+ pub fn allowed_by(&self, anchor: Permissions) -> bool {
match self {
- Self::Tab { .. } | Self::Split(DockSide::Center) => anchor.accepts_tabs,
+ Self::Tab { .. } | Self::Split(DockSide::Center) => anchor.accepts_tabs && anchor.shares_column,
+ Self::Group { .. } => anchor.shares_column,
Self::Split(_) | Self::SplitSized { .. } => anchor.accepts_splits,
- Self::Group { .. } if floating => anchor.accepts_splits,
- _ => true,
+ Self::Column { .. } | Self::Edge(_) => true,
}
}
}
diff --git a/crates/behavior/src/dock/apply.rs b/crates/behavior/src/dock/apply.rs
index 6e92e556f..d0e6a2a73 100644
--- a/crates/behavior/src/dock/apply.rs
+++ b/crates/behavior/src/dock/apply.rs
@@ -1,12 +1,14 @@
//! The public transactions of a layout: an action under permissions, atomic, with the panels it closed.
-use std::hash::Hash;
+use std::{collections::HashSet, hash::Hash};
use super::{
action::Action,
+ edit::{leaves, tree_panels},
groups::{Target, Unit},
inner::unit_of,
layout::Layout,
+ node::Node,
policy::{DockError, Permissions},
};
@@ -19,12 +21,14 @@ impl {
/// Check application policy before making an atomic change, and return the panels the
/// action closed (see [`Self::closed_by`]) so the application can release their state.
/// The callback must be stable throughout one call. Registry validation remains with the
- /// application, particularly Open.
+ /// application, particularly Open. The column rights ([`Permissions::collapses`],
+ /// [`Permissions::shares_column`]) are checked on the result: an action that leaves a panel breaking them,
+ /// which did not before, is refused, so a drag's dry run refuses it alike.
pub fn apply_with_permissions(&mut self, action: Action , permissions: impl Fn(&P) -> Permissions) -> Result {
}
action => action,
};
- // A destination in a floating window takes only floatable panels, and a group placed
- // there becomes a split of the anchor's frame.
+ // A destination in a floating window takes only floatable panels.
let floats = |anchor: &P| self.floating.iter().any(|w| w.contains(anchor));
match &action {
Action::Move { panel, anchor, placement } | Action::OpenAt { panel, anchor, placement } => {
@@ -46,7 +49,7 @@ impl {
if !opens && !permissions(panel).movable {
return Err(DockError::NotAllowed);
}
- if !placement.allowed_by(permissions(anchor), floats(anchor)) || floats(anchor) && !permissions(panel).floatable {
+ if !placement.allowed_by(permissions(anchor)) || floats(anchor) && !permissions(panel).floatable {
return Err(DockError::NotAllowed);
}
}
@@ -69,7 +72,7 @@ impl {
&& match to {
Target::Float { .. } => policy.floatable,
Target::At { anchor, placement } => {
- placement.allowed_by(permissions(anchor), floats(anchor)) && (!floats(anchor) || policy.floatable)
+ placement.allowed_by(permissions(anchor)) && (!floats(anchor) || policy.floatable)
}
Target::NewDock { .. } => true,
};
@@ -86,7 +89,7 @@ impl {
Target::Float { .. } if members.iter().any(|p| !permissions(p).floatable) => return Err(DockError::NotAllowed),
Target::At { anchor, placement }
if !members.contains(anchor)
- && (!placement.allowed_by(permissions(anchor), floats(anchor))
+ && (!placement.allowed_by(permissions(anchor))
|| floats(anchor) && members.iter().any(|p| !permissions(p).floatable)) =>
{
return Err(DockError::NotAllowed);
@@ -110,8 +113,46 @@ impl {
let mut proposed = self.clone();
proposed.apply_inner(action, &|p| permissions(p).is_protected())?;
proposed.validate()?;
- *self = proposed;
- Ok(closed)
+ if !proposed.breaks_columns_beyond(self, &permissions) {
+ *self = proposed;
+ return Ok(closed);
+ }
+ Err(DockError::NotAllowed)
+ }
+
+ /// Whether a panel breaks its column rights in this layout that did not in `before`.
+ pub(super) fn breaks_columns_beyond(&self, before: &Self, permissions: &impl Fn(&P) -> Permissions) -> bool {
+ let breaches = self.column_breaches(permissions);
+ !breaches.is_empty() && !breaches.is_subset(&before.column_breaches(permissions))
+ }
+
+ /// The panels that break their column rights: a panel that does not collapse ([`Permissions::collapses`]) in
+ /// a collapsed column, and every panel of a column (or node of the docked tree) that holds a panel that does
+ /// not share it ([`Permissions::shares_column`]) beside another panel.
+ pub(super) fn column_breaches(&self, permissions: &impl Fn(&P) -> Permissions) -> HashSet {
+ let mut breaches = HashSet::new();
+ let mut check = |panels: Vec<&P>, iconic: bool| {
+ if iconic {
+ breaches.extend(panels.iter().filter(|p| !permissions(p).collapses).map(|p| (*p).clone()));
+ }
+ if panels.len() > 1 && panels.iter().any(|p| !permissions(p).shares_column) {
+ breaches.extend(panels.into_iter().cloned());
+ }
+ };
+ for window in &self.floating {
+ check(window.panels().collect(), window.column.iconic);
+ }
+ for (leaf, _) in self.root.as_ref().map(leaves).unwrap_or_default() {
+ match leaf {
+ Node::Dock { columns, .. } => {
+ for column in columns {
+ check(column.panels().collect(), column.iconic);
+ }
+ }
+ leaf => check(tree_panels(leaf), false),
+ }
+ }
+ breaches
}
/// Apply every action in order, or none: the first rejection leaves the layout unchanged.
diff --git a/crates/behavior/src/dock/edit.rs b/crates/behavior/src/dock/edit.rs
index 791a97638..8d116bd79 100644
--- a/crates/behavior/src/dock/edit.rs
+++ b/crates/behavior/src/dock/edit.rs
@@ -87,43 +87,6 @@ pub fn first_active (root: &Node ) -> Option<&P> {
}
}
-/// The groups of a tree, first to last: what a dock column takes from a floating window.
-pub(crate) fn tree_groups ) -> Vec (groups: Vec | g.height.filter(|h| h.is_finite() && *h > 0.0);
- let known: Vec (root: &mut Node , path: &[bool], new: Node , zone: DockSide) -> bool {
@@ -194,10 +157,8 @@ impl {
/// The place of `panel`, or `None` when it is absent.
pub fn place(&self, panel: &P) -> Option {
None
}
- /// The `Tabs` or `Stack` node at a tree place.
+ /// The `Tabs` or `Stack` node at a place of the docked tree.
pub fn node_of(&self, place: &PanelPlace) -> Option<&Node > {
- let (window, path) = place.tree_path()?;
- node_at(self.tree(window)?, path)
+ node_at(self.root.as_ref()?, place.tree_path()?)
}
/// The path of the `Dock` node on `side`, when the layout has one.
@@ -296,21 +256,37 @@ impl {
docked.iter().find(|p| protected(p) == narrowed).or(docked.first()).map(|p| (*p).clone())
}
- /// The dock column at `place`; `None` for a place outside a dock.
+ /// The column at `place`: a dock column or a floating window's column; `None` for a node of the docked tree.
pub fn column(&self, place: &PanelPlace) -> Option<&Column > {
- let PanelPlace::Dock { path, column, .. } = place else { return None };
- match self.root.as_ref().and_then(|root| node_at(root, path)) {
- Some(Node::Dock { columns, .. }) => columns.get(*column),
- _ => None,
+ match place {
+ PanelPlace::Dock { path, column, .. } => match self.root.as_ref().and_then(|root| node_at(root, path)) {
+ Some(Node::Dock { columns, .. }) => columns.get(*column),
+ _ => None,
+ },
+ PanelPlace::Floating { window, .. } => self.floating.get(*window).map(|w| &w.column),
+ PanelPlace::Node(_) => None,
}
}
- /// The dock group at `place`; `None` for a `Tabs` or `Stack` node.
+ /// The group at `place` of a dock column or a floating window; `None` for a `Tabs` or `Stack` node.
pub fn group(&self, place: &PanelPlace) -> Option<&Group > {
- match place {
- PanelPlace::Dock { group, .. } => self.column(place)?.groups.get(*group),
- PanelPlace::Node(_) | PanelPlace::Floating { .. } => None,
- }
+ self.column(place)?.groups.get(place.group_index()?)
+ }
+
+ /// Whether opening `panel` shows its column's flyout instead of the column: its column is collapsed to icons.
+ pub fn opens_in_flyout(&self, panel: &P) -> bool {
+ self.place(panel).is_some_and(|place| self.column(&place).is_some_and(|column| column.iconic))
+ }
+}
+
+/// A column without its sizes: its groups and their state, and whether it is collapsed.
+fn column_shape ) -> Column {
+ Column {
+ groups: column.groups.iter().map(|g| Group { height: None, flyout_width: None, flyout_offset: None, ..g.clone() }).collect(),
+ width: None,
+ iconic: column.iconic,
+ iconic_width: None,
+ steps: None,
}
}
@@ -344,49 +320,21 @@ impl {
}
Node::Tabs { panels, active } => Node::Tabs { panels: panels.clone(), active: *active },
Node::Stack { entries } => Node::Stack { entries: entries.iter().map(|e| StackEntry { height: None, ..e.clone() }).collect() },
- Node::Dock { side, columns } => Node::Dock {
- side: *side,
- columns: columns
- .iter()
- .map(|c| Column {
- groups: c.groups.iter().map(|g| Group { height: None, flyout_width: None, flyout_offset: None, ..g.clone() }).collect(),
- width: None,
- iconic: c.iconic,
- iconic_width: None,
- })
- .collect(),
- },
+ Node::Dock { side, columns } => Node::Dock { side: *side, columns: columns.iter().map(column_shape).collect() },
}
}
Layout {
root: self.root.as_ref().map(node),
- floating: self.floating.iter().map(|w| Floating { root: node(&w.root), rect: Rect::ZERO, native: None, ..w.clone() }).collect(),
+ floating: self
+ .floating
+ .iter()
+ .map(|w| Floating { column: column_shape(&w.column), rect: Rect::ZERO, native: None, edge: None, ..w.clone() })
+ .collect(),
}
}
- /// The docked layout (`None`) or a floating window's tree.
- pub(crate) fn tree(&self, window: Option > {
- match window {
- None => self.root.as_ref(),
- Some(window) => self.floating.get(window).map(|w| &w.root),
- }
- }
-
- pub(super) fn tree_mut(&mut self, window: Option > {
- match window {
- None => self.root.as_mut(),
- Some(window) => self.floating.get_mut(window).map(|w| &mut w.root),
- }
- }
-
- /// The docked layout's tree, then each floating window's.
- pub(super) fn trees_mut(&mut self) -> impl Iterator > {
- let (window, path) = place.tree_path()?;
- node_at_mut(self.tree_mut(window)?, path)
+ node_at_mut(self.root.as_mut()?, place.tree_path()?)
}
pub(super) fn columns_mut(&mut self, path: &[bool]) -> Option<&mut Vec {
}
pub(super) fn column_mut(&mut self, place: &PanelPlace) -> Option<&mut Column > {
- let PanelPlace::Dock { path, column, .. } = place else { return None };
- self.columns_mut(path)?.get_mut(*column)
+ match place {
+ PanelPlace::Dock { path, column, .. } => self.columns_mut(path)?.get_mut(*column),
+ PanelPlace::Floating { window, .. } => self.floating.get_mut(*window).map(|w| &mut w.column),
+ PanelPlace::Node(_) => None,
+ }
}
pub(super) fn group_mut(&mut self, place: &PanelPlace) -> Option<&mut Group > {
+ let group = place.group_index()?;
+ self.column_mut(place)?.groups.get_mut(group)
+ }
+
+ /// The state a new column made of groups taken from the column at `place` keeps ([`Column::emptied`]), with a
+ /// floating window's width; no state for a place outside a column.
+ pub(super) fn source_column(&self, place: &PanelPlace) -> Column {
+ let mut state = self.column(place).map_or_else(|| Column::new(Vec::new()), Column::emptied);
+ if let PanelPlace::Floating { window, .. } = place
+ && let Some(window) = self.floating.get(*window)
+ {
+ state.width = Some(window.rect.width());
+ }
+ state
+ }
+
+ /// Removes the column at `place` when it holds no group: a dock column (and its dock when that empties too), or
+ /// a floating window. Returns the id of a window it removed.
+ fn drop_if_empty(&mut self, place: &PanelPlace) -> Option {
pub(super) fn members(&self, panel: &P, unit: Unit) -> Result {
}
}
- /// Detaches the panel's group, keeping its dock dimensions and floating-window geometry. A stack entry becomes a
- /// single-panel group with its saved height.
+ /// Detaches the panel's group with the state of the column it leaves; a floating window's last group carries
+ /// the window's id. A stack entry becomes a single-panel group with its saved height.
pub(super) fn take_group(&mut self, panel: &P) -> Result | match source {
- Some((rect, minimized, id)) if path.is_empty() => Moving { width: Some(rect.width()), minimized, id: Some(id), ..moving },
- Some((rect, ..)) => Moving { width: Some(rect.width()), ..moving },
- None => moving,
- };
- if let Some(Node::Stack { entries }) = self.node_of_mut(&place)
- && entries.len() > 1
- && let Some(index) = entries.iter().position(|e| &e.panel == panel)
- {
- let entry = entries.remove(index);
- let group = Group {
- panels: vec![entry.panel],
- active: 0,
- minimized: !entry.open,
- height: entry.height,
- flyout_width: None,
- flyout_offset: None,
- };
- let moving = whole(Moving::group(group));
- return Ok(Moving { id: None, ..moving });
- }
- match self.take_node_in(window, &path) {
- Some(Node::Tabs { panels, active }) => Ok(whole(Moving::group(Group::new(panels, active)))),
- Some(Node::Stack { mut entries }) if entries.len() == 1 => {
- let entry = entries.remove(0);
- Ok(whole(Moving::group(Group {
- panels: vec![entry.panel],
- active: 0,
- minimized: !entry.open,
- height: entry.height,
- flyout_width: None,
- flyout_offset: None,
- })))
- }
- _ => Err(DockError::MissingPanel),
- }
+ let PanelPlace::Node(path) = &place else {
+ let source = self.source_column(&place);
+ let group = place.group_index().ok_or(DockError::MissingPanel)?;
+ let column = self.column_mut(&place).ok_or(DockError::MissingPanel)?;
+ if group >= column.groups.len() {
+ return Err(DockError::MissingPanel);
}
- PanelPlace::Dock { path, column, group } => {
+ let taken = column.groups.remove(group);
+ let id = self.drop_if_empty(&place);
+ return Ok(Moving { id, ..Moving::taken(taken, source) });
+ };
+ if let Some(Node::Stack { entries }) = self.node_of_mut(&place)
+ && entries.len() > 1
+ && let Some(index) = entries.iter().position(|e| &e.panel == panel)
+ {
+ return Ok(Moving::group(entries.remove(index).into_group()));
+ }
+ match self.take_node(path) {
+ Some(Node::Tabs { panels, active }) => Ok(Moving::group(Group::new(panels, active))),
+ Some(Node::Stack { mut entries }) if entries.len() == 1 => Ok(Moving::group(entries.remove(0).into_group())),
+ _ => Err(DockError::MissingPanel),
+ }
+ }
+
+ /// Detaches the panel's column: a dock column, or a floating window's, which takes the window's width and id
+ /// along.
+ pub(super) fn take_column(&mut self, panel: &P) -> Result , to: Target , canvas: &dyn Fn(&P) -> bool) -> Result<(), DockError> {
- if moving.groups.is_empty() || moving.groups.iter().any(|g| g.panels.is_empty()) {
+ let mut moving = moving;
+ if moving.column.groups.is_empty() || moving.column.groups.iter().any(|g| g.panels.is_empty()) {
return Err(DockError::MissingPanel);
}
match to {
- Target::Float { rect } => {
+ Target::Float { rect, edge } => {
if !valid_rect(rect) {
return Err(DockError::InvalidGeometry);
}
- let root = match moving.node {
- Some(node) => node,
- None => stack_tree(moving.groups).ok_or(DockError::MissingPanel)?,
- };
- let window = Floating { minimized: moving.minimized, ..Floating::new(root, rect) };
- self.floating.push(Floating { id: moving.id.unwrap_or(window.id), ..window });
+ // A window's width is its rect's; only a collapsed column keeps to an edge of its own.
+ let window = Floating::new(Column { width: None, ..moving.column }, rect);
+ let edge = edge.filter(|_| window.column.iconic);
+ self.floating.push(Floating { id: moving.id.unwrap_or(window.id), edge, ..window });
Ok(())
}
Target::NewDock { side } => {
@@ -627,48 +550,32 @@ impl {
self.merge(&place, index, moving)
}
DockPlacement::Split(zone) => {
- 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(root, path, new, zone) { Ok(()) } else { Err(DockError::MissingTarget) }
+ let path = place.tree_path().ok_or(DockError::InvalidPlacement)?;
+ let (panels, active) = flatten(moving.column.groups);
+ let root = self.root.as_mut().ok_or(DockError::MissingTarget)?;
+ if split_frame(root, path, Node::Tabs { panels, active }, zone) { Ok(()) } else { Err(DockError::MissingTarget) }
}
DockPlacement::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.
- DockPlacement::Group { below, .. } if matches!(place, PanelPlace::Floating { .. }) => {
- let zone = if below { DockSide::Bottom } else { DockSide::Top };
- self.insert_moving(moving, Target::At { anchor, placement: DockPlacement::Split(zone) }, canvas)
+ let path = place.tree_path().ok_or(DockError::InvalidPlacement)?;
+ let (panels, active) = flatten(moving.column.groups);
+ let root = self.root.as_mut().ok_or(DockError::MissingTarget)?;
+ if split_frame_sized(root, path, Node::Tabs { panels, active }, zone, size, outer) {
+ Ok(())
+ } else {
+ Err(DockError::InvalidPlacement)
+ }
}
DockPlacement::Group { below, height } => {
if !valid_height(height) {
return Err(DockError::InvalidGeometry);
}
- let mut moving = moving;
if height.is_some() {
- moving.groups.iter_mut().for_each(|group| group.height = height);
+ moving.column.groups.iter_mut().for_each(|group| group.height = height);
}
- let (groups, index) = match &place {
- PanelPlace::Dock { group, .. } => (&mut self.column_mut(&place).ok_or(DockError::MissingTarget)?.groups, *group),
- PanelPlace::Node(_) | PanelPlace::Floating { .. } => return Err(DockError::InvalidPlacement),
- };
+ let index = place.group_index().ok_or(DockError::InvalidPlacement)?;
+ let groups = &mut self.column_mut(&place).ok_or(DockError::MissingTarget)?.groups;
let index = (index + usize::from(below)).min(groups.len());
- groups.splice(index..index, moving.groups);
+ groups.splice(index..index, moving.column.groups);
Ok(())
}
DockPlacement::Edge(zone) => {
@@ -681,7 +588,7 @@ impl {
if matches!(node, Node::Dock { .. }) {
return Err(DockError::InvalidPlacement);
}
- let (panels, active) = flatten(moving.groups);
+ let (panels, active) = flatten(moving.column.groups);
let new = Node::Tabs { panels, active };
let old = std::mem::replace(node, Node::Tabs { panels: Vec::new(), active: 0 });
let axis = if matches!(zone, DockSide::Top | DockSide::Bottom) { Axis::Y } else { Axis::X };
@@ -720,7 +627,7 @@ impl {
pub(super) fn index_in(&self, place: &PanelPlace, panel: &P) -> Option {
/// Join every moving panel to the group at `place`, before `index` or at the end. The first
/// moving group's active panel becomes active.
pub(super) fn merge(&mut self, place: &PanelPlace, index: Option ) -> Result<(), DockError> {
- let (panels, selected) = flatten(moving.groups);
+ let (panels, selected) = flatten(moving.column.groups);
match place {
- PanelPlace::Node(_) | PanelPlace::Floating { .. } => match self.node_of_mut(place) {
+ PanelPlace::Node(_) => match self.node_of_mut(place) {
Some(Node::Tabs { panels: target, active }) => {
splice(target, active, index.unwrap_or(target.len()), panels, selected);
Ok(())
@@ -771,5 +678,5 @@ pub(super) fn flatten (groups: Vec , usize) {
}
pub(super) fn valid_column (column: &Column ) -> bool {
- column.width.is_none_or(valid_width) && column.iconic_width.is_none_or(valid_width)
+ column.width.is_none_or(valid_width) && column.iconic_width.is_none_or(valid_width) && column.steps != Some(0)
}
diff --git a/crates/behavior/src/dock/groups.rs b/crates/behavior/src/dock/groups.rs
index 38475c93e..a05570c53 100644
--- a/crates/behavior/src/dock/groups.rs
+++ b/crates/behavior/src/dock/groups.rs
@@ -18,7 +18,7 @@ pub enum DockEdge {
End,
}
-/// Tabs that move, minimize and size together in a dock column.
+/// Tabs that move, minimize and size together in a column, docked or floating.
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(bound(deserialize = "P: serde::Deserialize<'de>"))]
#[non_exhaustive]
@@ -55,7 +55,7 @@ impl Group {
}
}
-/// One column of a dock: groups from top to bottom.
+/// One column of groups from top to bottom: a column of a dock, or the whole of a floating window.
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(bound(deserialize = "P: serde::Deserialize<'de>"))]
#[non_exhaustive]
@@ -63,14 +63,20 @@ pub struct Column {
/// The groups, top to bottom.
pub groups: Vec (column: &Column , side: Option Column {
/// A column of `groups`, expanded at the theme's column width until the user resizes it.
pub fn new(groups: Vec Column {
self.width = Some(width);
self
}
+
+ /// The column collapsed to icons, or expanded.
+ #[must_use]
+ pub fn with_iconic(mut self, iconic: bool) -> Self {
+ self.iconic = iconic;
+ self
+ }
+
+ /// The column `steps` content columns wide ([`Self::steps`]).
+ #[must_use]
+ pub fn with_steps(mut self, steps: u16) -> Self {
+ self.steps = Some(steps);
+ self
+ }
+
+ /// Every panel of the column, top group first.
+ pub fn panels(&self) -> impl Iterator {
/// `[x, y, width, height]`.
#[serde(with = "crate::dock::rect_serde")]
rect: Rect,
+ /// The new window's [`Floating::edge`](super::Floating::edge) when its column is collapsed: the edge the area
+ /// decided from where the strip was dropped. `None` (and any expanded column) leaves the edge to the area,
+ /// nearer `rect`.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ edge: Option {
///
/// | Anchor in | `Center` | `Top`, `Bottom` | `Start`, `End` |
/// |---|---|---|---|
- /// | the split tree or a floating window | [`DockPlacement::Split`] | `Split` | `Split` |
+ /// | the split tree | [`DockPlacement::Split`] | `Split` | `Split` |
/// | a dock column | `Split(Center)` (join as tabs) | [`DockPlacement::Group`] above or below | [`DockPlacement::Column`] on that side |
+ /// | a floating window | `Split(Center)` (join as tabs) | `Group` above or below | refused ([`DockError::InvalidPlacement`]) |
///
- /// A dock's `Column { after }` counts from its window edge, which is the dock's [`DockEdge`] in reading order;
- /// this picks `after` so the new column lands on the side of the anchor's column.
+ /// A floating window is one column, so nothing goes beside it. A dock's `Column { after }` counts from its
+ /// window edge, which is the dock's [`DockEdge`] in reading order; this picks `after` so the new column lands on
+ /// the side of the anchor's column.
pub fn for_zone(layout: &Layout , anchor: &P, side: DockSide) -> Result {
}
/// What the Window menu shows for a panel. The model does not track the z-order of floating
-/// windows, so `Front` means "showing": the active tab of an expanded group in an expanded column.
+/// windows, so `Front` means "showing": the active tab of an expanded group in an expanded column, docked or
+/// floating.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum PanelState {
@@ -185,7 +239,7 @@ pub enum PanelState {
Front,
}
-/// The group a closed panel was in, when that group was in a dock.
+/// The group a closed panel was in, when that group was in a column, docked or floating.
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct GroupLocation {
@@ -199,7 +253,7 @@ pub struct GroupLocation {
/// The offset in points of the group's flyout top from its icons' top, if the user had moved it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub flyout_offset: Option {
- pub groups: Vec ,
+ /// The id of a floating window whose last group is in transit, which a new window keeps.
pub id: Option Moving {
+ /// `group` with no column state: a new column made of it is expanded at the theme's width.
pub(super) fn group(group: Group ) -> Self {
- Self { groups: vec![group], node: None, minimized: false, width: None, iconic: false, iconic_width: None, id: None }
+ Self::taken(group, Column::new(Vec::new()))
}
+ /// `group` taken out of a column whose state is `source` ([`Column::emptied`]).
+ pub(super) fn taken(group: Group , source: Column ) -> Self {
+ Self { column: Column { groups: vec![group], ..source }, id: None }
+ }
+
+ /// The column a new dock column gets: the moving column, `width` points wide unless it brings a width.
pub(super) fn into_column(self, width: Option {
- Column { groups: self.groups, width: self.width.or(width), iconic: self.iconic, iconic_width: self.iconic_width }
+ Column { width: self.column.width.or(width), ..self.column }
}
}
@@ -298,8 +366,13 @@ impl Target {
Self::NewDock { side }
}
- /// Builds [`Target::Float`].
+ /// Builds [`Target::Float`] with no edge: the area takes the edge nearer `rect`.
pub fn float(rect: Rect) -> Self {
- Self::Float { rect }
+ Self::Float { rect, edge: None }
+ }
+
+ /// Builds [`Target::Float`] with the edge a collapsed window keeps to.
+ pub fn float_with_edge(rect: Rect, edge: Option {
return Err(DockError::MissingTarget);
}
}
+ let source = self.source_of(&panel);
let entry = self.take(&panel).ok_or(DockError::MissingPanel)?;
- self.insert(entry, &anchor, placement, canvas)
+ self.insert(entry, source, &anchor, placement, canvas)
}
Action::Float { panel, rect } => {
- if !valid_rect(rect) {
- return Err(DockError::InvalidGeometry);
- }
// A window's only panel keeps the window's id.
let lone = self.floating.iter().find(|w| w.contains(&panel)).filter(|w| w.panels().count() == 1).map(|w| w.id);
+ let source = self.source_of(&panel);
// A panel the layout does not hold opens in the new window.
let entry = self.take(&panel).unwrap_or(StackEntry { panel: panel.clone(), open: true, height: None });
- let window = Floating::single(vec![entry.panel], 0, rect);
- self.floating.push(Floating { id: lone.unwrap_or(window.id), ..window });
- Ok(())
+ let moving = Moving { id: lone, ..Moving::taken(Group::new(vec![entry.panel], 0), source) };
+ self.insert_moving(moving, Target::Float { rect, edge: None }, canvas)
}
Action::Close { panel } => self.take(&panel).map(|_| ()).ok_or(DockError::MissingPanel),
Action::Activate { panel } => {
@@ -61,12 +61,7 @@ impl {
group.minimized = false;
return Ok(());
}
- if let PanelPlace::Floating { window, .. } = place
- && let Some(window) = self.floating.get_mut(window)
- {
- window.minimized = false;
- }
- if self.trees_mut().any(|node| activate(node, &panel)) {
+ if self.root.as_mut().is_some_and(|root| activate(root, &panel)) {
return Ok(());
}
Err(DockError::MissingPanel)
@@ -77,7 +72,7 @@ impl {
}
let entry = StackEntry { panel, open: true, height: None };
if let Some(anchor) = anchor {
- self.insert(entry, &anchor, DockPlacement::Tab { before: None }, canvas)
+ self.insert(entry, Column::new(Vec::new()), &anchor, DockPlacement::Tab { before: None }, canvas)
} else if self.root.is_none() {
self.root = Some(Node::Tabs { panels: vec![entry.panel], active: 0 });
Ok(())
@@ -94,14 +89,15 @@ impl {
{
return Err(DockError::MissingTarget);
}
- self.insert(StackEntry { panel, open: true, height: None }, &anchor, placement, canvas)
+ self.insert(StackEntry { panel, open: true, height: None }, Column::new(Vec::new()), &anchor, placement, canvas)
}
- Action::MoveFloating { panel, rect } => {
+ Action::MoveFloating { panel, rect, edge } => {
if !valid_rect(rect) {
return Err(DockError::InvalidGeometry);
}
let window = self.floating.iter_mut().find(|g| g.contains(&panel)).ok_or(DockError::MissingPanel)?;
window.rect = rect;
+ window.edge = edge;
Ok(())
}
Action::ResizeSplit { path, size } => {
@@ -113,18 +109,8 @@ impl {
}
resize_split(self.root.as_mut().ok_or(DockError::MissingTarget)?, &path, size)
}
- Action::ResizeWindowSplit { panel, path, size } => {
- if path.len() >= MAX_DEPTH {
- return Err(DockError::LimitExceeded);
- }
- if !valid_size(size) {
- return Err(DockError::InvalidGeometry);
- }
- let window = self.floating.iter_mut().find(|w| w.contains(&panel)).ok_or(DockError::MissingPanel)?;
- resize_split(&mut window.root, &path, size)
- }
Action::SetStackOpen { panel, open } => {
- let entry = self.trees_mut().find_map(|n| stack_entry_mut(n, &panel)).ok_or(DockError::MissingPanel)?;
+ let entry = self.stack_entry_mut(&panel).ok_or(DockError::MissingPanel)?;
entry.open = open;
Ok(())
}
@@ -132,7 +118,7 @@ impl {
if !valid_height(height) {
return Err(DockError::InvalidGeometry);
}
- let entry = self.trees_mut().find_map(|n| stack_entry_mut(n, &panel)).ok_or(DockError::MissingPanel)?;
+ let entry = self.stack_entry_mut(&panel).ok_or(DockError::MissingPanel)?;
entry.height = height;
Ok(())
}
@@ -154,8 +140,9 @@ impl {
Action::MovePanel { panel, to } => match to {
Target::At { anchor, placement } => self.apply_inner(Action::Move { panel, anchor, placement }, canvas),
to => {
+ let source = self.source_of(&panel);
let entry = self.take(&panel).ok_or(DockError::MissingPanel)?;
- self.insert_moving(Moving::group(Group::new(vec![entry.panel], 0)), to, canvas)
+ self.insert_moving(Moving::taken(Group::new(vec![entry.panel], 0), source), to, canvas)
}
},
Action::CloseGroup { ref panel } | Action::CloseWindow { ref panel } => self.take_unit(panel, unit_of(&action)).map(|_| ()),
@@ -173,11 +160,7 @@ impl {
group.minimized = minimized;
return Ok(());
}
- if let PanelPlace::Floating { window, .. } = place {
- self.floating.get_mut(window).ok_or(DockError::MissingPanel)?.minimized = minimized;
- return Ok(());
- }
- let entry = self.trees_mut().find_map(|n| stack_entry_mut(n, &panel)).ok_or(DockError::InvalidPlacement)?;
+ let entry = self.stack_entry_mut(&panel).ok_or(DockError::InvalidPlacement)?;
entry.open = !minimized;
Ok(())
}
@@ -190,7 +173,7 @@ impl {
group.height = height;
return Ok(());
}
- let entry = self.trees_mut().find_map(|n| stack_entry_mut(n, &panel)).ok_or(DockError::InvalidPlacement)?;
+ let entry = self.stack_entry_mut(&panel).ok_or(DockError::InvalidPlacement)?;
entry.height = height;
Ok(())
}
@@ -212,13 +195,35 @@ impl {
}
Action::SetIconic { panel, iconic } => {
self.column_of(&panel)?.iconic = iconic;
+ // A floating column that collapses hangs from the edge nearer its window, which the area takes.
+ if iconic && let Some(window) = self.floating.iter_mut().find(|window| window.contains(&panel)) {
+ window.edge = None;
+ }
Ok(())
}
Action::ResizeColumn { panel, width } => {
if !valid_width(width) {
return Err(DockError::InvalidGeometry);
}
- self.column_of(&panel)?.width = Some(width);
+ let place = self.place(&panel).ok_or(DockError::MissingPanel)?;
+ // A stepped column's width is its step count.
+ if self.column(&place).ok_or(DockError::InvalidPlacement)?.steps.is_some() {
+ return Err(DockError::InvalidPlacement);
+ }
+ if let PanelPlace::Floating { window, .. } = place {
+ // A floating column is as wide as its window.
+ let window = self.floating.get_mut(window).ok_or(DockError::MissingPanel)?;
+ window.rect = Rect::from_min_size(window.rect.min, vec2(width, window.rect.height()));
+ } else {
+ self.column_of(&panel)?.width = Some(width);
+ }
+ Ok(())
+ }
+ Action::SetColumnSteps { panel, steps } => {
+ if steps == 0 {
+ return Err(DockError::InvalidGeometry);
+ }
+ self.column_of(&panel)?.steps = Some(steps);
Ok(())
}
Action::ResizeIconic { panel, width } => {
@@ -240,11 +245,23 @@ impl {
}
}
+ /// The column holding `panel`, docked or floating.
pub(super) fn column_of(&mut self, panel: &P) -> Result<&mut Column , DockError> {
let place = self.place(panel).ok_or(DockError::MissingPanel)?;
self.column_mut(&place).ok_or(DockError::InvalidPlacement)
}
+ /// The state a new column made of `panel` keeps: its column's ([`Self::source_column`]), or none for a panel
+ /// outside a column or absent.
+ pub(super) fn source_of(&self, panel: &P) -> Column {
+ self.place(panel).map_or_else(|| Column::new(Vec::new()), |place| self.source_column(&place))
+ }
+
+ /// The accordion entry of `panel` in the docked tree.
+ pub(super) fn stack_entry_mut(&mut self, panel: &P) -> Option<&mut StackEntry > {
+ stack_entry_mut(self.root.as_mut()?, panel)
+ }
+
pub(super) fn same_group(&self, panel: &P, anchor: &P) -> bool {
let place = self.place(panel);
place.is_some() && place == self.place(anchor)
@@ -256,24 +273,20 @@ impl {
if removed.is_some() {
return removed;
}
- if let Some(index) = self.floating.iter().position(|w| w.contains(panel))
- && let Some(window) = self.floating.get_mut(index)
- {
- let root = std::mem::replace(&mut window.root, Node::Tabs { panels: Vec::new(), active: 0 });
- match remove_node(root, panel, &mut removed) {
- Some(root) => window.root = root,
- None => {
- self.floating.remove(index);
- }
- }
+ let index = self.floating.iter().position(|w| w.contains(panel))?;
+ let window = self.floating.get_mut(index)?;
+ let removed = remove_from_column(&mut window.column, panel);
+ if window.column.groups.is_empty() {
+ self.floating.remove(index);
}
removed
}
- /// Where [`Action::Open`] without an anchor puts an absent panel in a layout with a root:
+ /// Where [`Action::Open`] without an anchor puts an absent `panel` in a layout with a root:
/// the end of the first shown dock group that accepts tabs, in the end-side dock if one has
- /// such a group, else a new frame at the end edge of the docked area.
- pub(super) fn open_place(&self, permissions: impl Fn(&P) -> Permissions) -> Option<(P, DockPlacement )> {
+ /// such a group, else a new frame at the end edge of the docked area. A panel that shares no column
+ /// ([`Permissions::shares_column`]) joins no group.
+ pub(super) fn open_place(&self, panel: &P, permissions: impl Fn(&P) -> Permissions) -> Option<(P, DockPlacement )> {
let docked: Vec<(&P, PanelPlace)> = self
.panels()
.into_iter()
@@ -292,7 +305,11 @@ impl {
PanelPlace::Dock { group, .. } => self.column(place).is_some_and(|c| !c.iconic && c.groups.get(*group).is_some_and(|g| !g.minimized)),
_ => false,
};
- let groups = docked.iter().filter(|(p, place)| side(place).is_some() && shown(place) && permissions(p).accepts_tabs);
+ let joins = permissions(panel).shares_column;
+ let groups = docked.iter().filter(|(p, place)| {
+ let anchor = permissions(p);
+ joins && side(place).is_some() && shown(place) && anchor.accepts_tabs && anchor.shares_column
+ });
if let Some((panel, _)) = groups.clone().find(|(_, place)| side(place) == Some(DockEdge::End)).or_else(|| groups.clone().next()) {
return Some(((*panel).clone(), DockPlacement::Tab { before: None }));
}
@@ -301,22 +318,26 @@ impl {
edge.map(|(panel, _)| ((*panel).clone(), DockPlacement::Edge(DockSide::End)))
}
+ /// Put `entry` at `placement` relative to `anchor`. `source` is the state of the column the panel left
+ /// ([`Self::source_of`]), which a new column made of it keeps.
pub(super) fn insert(
&mut self,
entry: StackEntry ,
+ source: Column ,
anchor: &P,
placement: DockPlacement ,
canvas: &dyn Fn(&P) -> bool,
) -> Result<(), DockError> {
let place = self.place(anchor).ok_or(DockError::MissingTarget)?;
- let tree = place.tree_path().map(|(window, path)| (window, path.to_vec()));
- let Some((window, path)) =
- tree.filter(|_| !matches!(placement, DockPlacement::Group { .. } | DockPlacement::Column { .. } | DockPlacement::Edge(_)))
+ let Some(path) = place
+ .tree_path()
+ .filter(|_| !matches!(placement, DockPlacement::Group { .. } | DockPlacement::Column { .. } | DockPlacement::Edge(_)))
+ .map(<[bool]>::to_vec)
else {
- let group = Group::new(vec![entry.panel], 0);
- return self.insert_moving(Moving::group(group), Target::At { anchor: anchor.clone(), placement }, canvas);
+ let moving = Moving::taken(Group::new(vec![entry.panel], 0), source);
+ return self.insert_moving(moving, Target::At { anchor: anchor.clone(), placement }, canvas);
};
- let root = self.tree_mut(window).ok_or(DockError::MissingTarget)?;
+ let root = self.root.as_mut().ok_or(DockError::MissingTarget)?;
if let DockPlacement::Split(zone) = placement
&& zone != DockSide::Center
{
@@ -435,12 +456,9 @@ pub(super) fn remove_node , panel: &P, removed: &mut
// A dock that was already empty stays; one emptied by this removal collapses.
let had_columns = !columns.is_empty();
for column in &mut columns {
- for group in &mut column.groups {
- if let Some(panel) = remove_tab(&mut group.panels, &mut group.active, panel) {
- *removed = Some(StackEntry { panel, open: true, height: None });
- }
+ if let Some(entry) = remove_from_column(column, panel) {
+ *removed = Some(entry);
}
- column.groups.retain(|g| !g.panels.is_empty());
}
columns.retain(|c| !c.groups.is_empty());
(!had_columns || !columns.is_empty()).then_some(Node::Dock { side, columns })
@@ -448,6 +466,18 @@ pub(super) fn remove_node , panel: &P, removed: &mut
}
}
+/// Removes `panel` from the groups of `column`, dropping a group it empties.
+pub(super) fn remove_from_column , panel: &P) -> Option (mut node: &mut Node , path: &[bool], size: SplitSize) -> Result<(), DockError> {
for second_child in path {
let Node::Split { first, second, .. } = node else { return Err(DockError::MissingTarget) };
diff --git a/crates/behavior/src/dock/layout.rs b/crates/behavior/src/dock/layout.rs
index 467ef40c7..ec3d68d10 100644
--- a/crates/behavior/src/dock/layout.rs
+++ b/crates/behavior/src/dock/layout.rs
@@ -98,26 +98,15 @@ impl {
}
}
for floating in &self.floating {
- if !valid_rect(floating.rect) {
+ if !valid_rect(floating.rect) || !valid_column(&floating.column) || floating.column.groups.is_empty() {
return Err(DockError::InvalidGeometry);
}
- let mut visit = vec![(&floating.root, 1usize)];
- while let Some((node, depth)) = visit.pop() {
- count = count.saturating_add(1);
- if depth > MAX_DEPTH || count > MAX_NODES {
- return Err(DockError::LimitExceeded);
- }
- match node {
- Node::Split { size, first, second, .. } => {
- if !valid_size(*size) {
- return Err(DockError::InvalidGeometry);
- }
- visit.push((second, depth + 1));
- visit.push((first, depth + 1));
- }
- Node::Dock { .. } => return Err(DockError::InvalidPlacement),
- Node::Tabs { .. } | Node::Stack { .. } => check_leaf(node, &mut seen)?,
- }
+ count = count.saturating_add(floating.column.groups.len().saturating_add(1));
+ if count > MAX_NODES {
+ return Err(DockError::LimitExceeded);
+ }
+ for group in &floating.column.groups {
+ check_group(group, &mut seen)?;
}
}
Ok(())
@@ -177,11 +166,11 @@ impl {
.is_ok()
}
- /// The anchor and placement that move `panel`'s dock group past its neighbour in the column.
+ /// The anchor and placement that move `panel`'s group past its neighbour in its column, docked or floating.
/// `pinned` panels stay put: the group and its neighbour must hold none.
pub(super) fn step_target(&self, panel: &P, up: bool, pinned: &dyn Fn(&P) -> bool) -> Result<(P, DockPlacement ), DockError> {
let place = self.place(panel).ok_or(DockError::MissingPanel)?;
- let PanelPlace::Dock { group, .. } = place else { return Err(DockError::InvalidPlacement) };
+ let group = place.group_index().ok_or(DockError::InvalidPlacement)?;
let groups = &self.column(&place).ok_or(DockError::MissingPanel)?.groups;
let neighbour = if up { group.checked_sub(1) } else { group.checked_add(1) }.and_then(|i| groups.get(i)).ok_or(DockError::MissingTarget)?;
let own = groups.get(group).ok_or(DockError::MissingPanel)?;
@@ -196,32 +185,26 @@ impl {
pub fn location(&self, panel: &P) -> Result {
Ok(location)
}
- /// Hidden, open behind another tab or in a collapsed container, or showing.
+ /// Hidden, open behind another tab or in a collapsed container, or showing. In a column, docked or floating,
+ /// a panel shows when it is its group's active tab, the group is not minimized and the column not collapsed.
pub fn panel_state(&self, panel: &P) -> PanelState {
let showing = match self.place(panel) {
None => return PanelState::Hidden,
- Some(place @ (PanelPlace::Node(_) | PanelPlace::Floating { .. })) => {
- let minimized = matches!(place, PanelPlace::Floating { window, .. } if self.floating.get(window).is_some_and(|w| w.minimized));
- !minimized
- && match self.node_of(&place) {
- Some(Node::Tabs { panels, active }) => panels.get(*active) == Some(panel),
- Some(Node::Stack { entries }) => entries.iter().any(|e| &e.panel == panel && e.open),
- _ => false,
- }
- }
+ Some(place @ PanelPlace::Node(_)) => match self.node_of(&place) {
+ Some(Node::Tabs { panels, active }) => panels.get(*active) == Some(panel),
+ Some(Node::Stack { entries }) => entries.iter().any(|e| &e.panel == panel && e.open),
+ _ => false,
+ },
Some(place) => {
let iconic = self.column(&place).is_some_and(|c| c.iconic);
self.group(&place).is_some_and(|g| !g.minimized && g.active_panel() == Some(panel)) && !iconic
@@ -288,11 +268,13 @@ impl {
!valid_height(s.height)
|| s.flyout_width.is_some_and(|w| !valid_width(w))
|| s.flyout_offset.is_some_and(|o| !valid_offset(o))
- || s.column.is_some_and(|c| c.width.is_some_and(|w| !valid_width(w)) || c.iconic_width.is_some_and(|w| !valid_width(w)))
+ || s.column.is_some_and(|c| {
+ c.width.is_some_and(|w| !valid_width(w)) || c.iconic_width.is_some_and(|w| !valid_width(w)) || c.steps == Some(0)
+ })
}) {
return Err(DockError::InvalidGeometry);
}
- // A restore that creates a group, column or dock gives it the saved state.
+ // A restore that creates a group, column, dock or window gives it the saved state.
let moving = || {
let group = Group {
panels: vec![panel.clone()],
@@ -303,12 +285,14 @@ impl {
flyout_offset: state.and_then(|s| s.flyout_offset),
};
let column = state.and_then(|s| s.column);
- Moving {
+ let source = Column {
+ groups: Vec::new(),
width: column.and_then(|c| c.width),
iconic: column.is_some_and(|c| c.iconic),
iconic_width: column.and_then(|c| c.iconic_width),
- ..Moving::group(group)
- }
+ steps: column.and_then(|c| c.steps),
+ };
+ Moving::taken(group, source)
};
let mut proposed = self.clone();
if location.floating.is_some_and(|rect| !valid_rect(rect)) {
@@ -317,7 +301,7 @@ impl {
let window_open = location.anchor.as_ref().is_some_and(|anchor| proposed.floating.iter().any(|w| w.contains(anchor)));
if let Some(rect) = location.floating.filter(|_| !window_open) {
// A window that closed as a whole reopens at its last rect.
- proposed.insert_moving(moving(), Target::Float { rect }, &|_| false)?;
+ proposed.insert_moving(moving(), Target::Float { rect, edge: None }, &|_| false)?;
} else if let Some(anchor) = &location.anchor
&& matches!(location.placement, DockPlacement::Group { .. } | DockPlacement::Column { .. })
{
@@ -325,15 +309,11 @@ impl {
return Err(DockError::MissingTarget);
}
proposed.insert_moving(moving(), Target::At { anchor: anchor.clone(), placement: location.placement.clone() }, &|_| false)?;
- } else if let Some(column) = state.and_then(|s| s.column).filter(|_| location.anchor.is_none()) {
+ } else if let Some(side) = state.and_then(|s| s.column).and_then(|c| c.side).filter(|_| location.anchor.is_none()) {
// Alone in its dock: back at that edge, as the outermost column if a dock exists.
- match proposed.dock_path(column.side) {
- Some(path) => {
- let columns = proposed.columns_mut(&path).ok_or(DockError::MissingTarget)?;
- let Moving { groups, .. } = moving();
- columns.insert(0, Column { groups, width: column.width, iconic: column.iconic, iconic_width: column.iconic_width });
- }
- None => proposed.insert_moving(moving(), Target::NewDock { side: column.side }, &|_| false)?,
+ match proposed.dock_path(side) {
+ Some(path) => proposed.columns_mut(&path).ok_or(DockError::MissingTarget)?.insert(0, moving().column),
+ None => proposed.insert_moving(moving(), Target::NewDock { side }, &|_| false)?,
}
} else if let Some(anchor) = &location.anchor {
if !proposed.contains(anchor) {
@@ -351,7 +331,7 @@ impl {
return Err(DockError::InvalidPlacement);
}
let size = location.size.unwrap_or(SplitSize::Ratio(0.5));
- around = proposed.trees_mut().any(|root| restore_around_subtree(root, &panel, &members, zone, size));
+ around = proposed.root.as_mut().is_some_and(|root| restore_around_subtree(root, &panel, &members, zone, size));
}
// A subtree that changed since (a migrated or reconciled layout) splits the anchor.
if !around {
@@ -361,8 +341,10 @@ impl {
placement => placement.clone(),
};
proposed.apply_inner(Action::OpenAt { panel: panel.clone(), anchor: anchor.clone(), placement }, &|_| false)?;
- if let Some(size) = location.size {
- proposed.trees_mut().any(|root| restore_parent_size(root, &panel, size));
+ if let Some(size) = location.size
+ && let Some(root) = proposed.root.as_mut()
+ {
+ restore_parent_size(root, &panel, size);
}
}
} else if proposed.root.is_none() {
@@ -370,13 +352,13 @@ impl {
} else {
return Err(DockError::MissingTarget);
}
- if let Some((open, height)) = location.stack {
- for root in proposed.trees_mut() {
- restore_stack_kind(root, &panel);
- if let Some(entry) = stack_entry_mut(root, &panel) {
- entry.open = open;
- entry.height = height;
- }
+ if let Some((open, height)) = location.stack
+ && let Some(root) = proposed.root.as_mut()
+ {
+ restore_stack_kind(root, &panel);
+ if let Some(entry) = stack_entry_mut(root, &panel) {
+ entry.open = open;
+ entry.height = height;
}
}
proposed.validate()?;
diff --git a/crates/behavior/src/dock/node.rs b/crates/behavior/src/dock/node.rs
index 7ceb6f998..b9b2f68cc 100644
--- a/crates/behavior/src/dock/node.rs
+++ b/crates/behavior/src/dock/node.rs
@@ -5,7 +5,6 @@ use emath::Rect;
use crate::{flow::Axis, placement::Placement};
use super::{
- edit::{stack_tree, tree_groups, tree_panels},
groups::{Column, DockEdge, Group},
split::SplitSize,
};
@@ -64,13 +63,12 @@ pub struct StackEntry {
pub height: Option {
/// loading keeps the saved id (or draws one when it is missing or taken), and merging
/// windows keeps the receiving window's.
pub id: u64,
- /// `Split`, `Tabs` and `Stack` nodes; a `Dock` is invalid here.
- pub root: Node ,
- /// The window's area in logical points, in the application's viewport. Saved as `[x, y, width, height]`.
+ /// The window's groups, top to bottom, and its collapsed state. Its `width` is unused: the window's width is
+ /// `rect`'s.
+ pub column: Column ,
+ /// The window's expanded area in logical points, in the application's viewport. Saved as
+ /// `[x, y, width, height]`.
pub rect: Rect,
/// Where the window is on the desktop while it is in its own OS window: the record app windows keep too, placed
/// with [`place`](crate::placement::place).
pub native: Option {
fn eq(&self, other: &Self) -> bool {
- self.root == other.root && self.rect == other.rect && self.native == other.native && self.minimized == other.minimized
+ self.column == other.column && self.rect == other.rect && self.native == other.native && self.edge == other.edge
}
}
@@ -115,6 +119,11 @@ impl StackEntry {
pub fn new(panel: P) -> Self {
Self { panel, open: true, height: None }
}
+
+ /// The section as a group of its own: minimized when the section was closed, at the section's height.
+ pub(super) fn into_group(self) -> Group {
+ Group { minimized: !self.open, height: self.height, ..Group::new(vec![self.panel], 0) }
+ }
}
/// A window id no other window of this process has drawn, from a random start so ids saved
@@ -131,16 +140,16 @@ pub(super) fn fresh_window_id() -> u64 {
}
impl Floating {
- /// A window holding `root`. Each call makes a new window, with a fresh [`Self::id`]: build
+ /// A window holding `column`. Each call makes a new window, with a fresh [`Self::id`]: build
/// a layout once and keep it, or give its windows ids with [`Self::with_id`]. A layout
/// built anew each frame without them opens new OS windows each frame.
- pub fn new(root: Node , rect: Rect) -> Self {
- Self { id: fresh_window_id(), root, rect, native: None, minimized: false }
+ pub fn new(column: Column , rect: Rect) -> Self {
+ Self { id: fresh_window_id(), column, rect, native: None, edge: None }
}
/// A window with one group. Each call makes a new window, as [`Self::new`] does.
pub fn single(panels: Vec , active: usize, rect: Rect) -> Self {
- Self::new(Node::Tabs { panels, active }, rect)
+ Self::new(Column::new(vec![Group::new(panels, active)]), rect)
}
/// The window with `id`, for a layout the app builds in code, such as a default layout:
@@ -151,24 +160,20 @@ impl Floating {
self
}
- /// Every panel in the window, in tree order.
+ /// Every panel in the window, top group first.
pub fn panels(&self) -> impl Iterator ] {
+ &self.column.groups
}
/// True when a group of this window holds `panel`. Takes any borrowed form of `P`, such
@@ -181,13 +186,27 @@ impl Floating {
}
}
+/// The saved shapes of a floating window, read by [`unique_ids`](floating_serde::unique_ids) into the windows of a
+/// layout:
+///
+/// | Saved shape | Becomes |
+/// |---|---|
+/// | v1 `{panels, active, rect}` | one window, one group |
+/// | v2 `{groups, rect}` | one window of those groups |
+/// | v3 `{root, rect, native, minimized}` | a window per part the tree's top splits side by side, each at its share of `rect`; each part's leaves in reading order become its groups (an accordion entry a group, minimized when its section was closed); `minimized` minimizes every group |
+/// | v4 `{column, rect, native, edge}` | one window |
+///
+/// The first window of a saved one keeps its id; the others get fresh ones.
pub(super) mod floating_serde {
+ use emath::{Rect, pos2, vec2};
use serde::de::IgnoredAny;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
- use super::{Floating, Group, Node, fresh_window_id};
- use crate::dock::edit::stack_tree;
+ use super::{Column, DockEdge, Floating, Group, Node, fresh_window_id};
+ use crate::dock::limits::MAX_NODES;
use crate::dock::rect_serde::{from_array, to_array};
+ use crate::dock::split::SplitSize;
+ use crate::flow::Axis;
use crate::placement::Placement;
#[derive(Serialize)]
@@ -199,34 +218,47 @@ pub(super) mod floating_serde {
}
#[derive(Serialize)]
- struct Tree<'a, P> {
+ struct V4<'a, P> {
id: u64,
- root: &'a Node ,
+ column: &'a Column ,
rect: [f32; 4],
#[serde(skip_serializing_if = "Option::is_none")]
native: Option<&'a Placement>,
- #[serde(skip_serializing_if = "std::ops::Not::not")]
- minimized: bool,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ edge: Option (column: &Column , group: &Group ) -> bool {
+ column.width.is_none()
+ && !column.iconic
+ && column.iconic_width.is_none()
+ && column.steps.is_none()
+ && !group.minimized
+ && group.height.is_none()
+ && group.flyout_width.is_none()
+ && group.flyout_offset.is_none()
}
impl {
fn serialize {
id: Option (PhantomData );
impl<'de, P: Deserialize<'de>> Visitor<'de> for V {
@@ -269,10 +302,22 @@ pub(super) mod floating_serde {
}
fn visit_map