From aa46612ac9d3ca98c62fe2cffd24c464830a677d Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 03:28:18 +0000 Subject: [PATCH] Dock area: a floating window draws its one column as a dock column does Pass::column shows a column, docked or floating: an IconicColumn while it is collapsed, else a DockColumn, with what the user did turned into actions in column_work. Each dock column calls it with its own bar; each floating window calls it inside a FloatingGroup with ColumnBar::Window, the title row being the column's bar: its double arrow sets the column iconic, and a collapsed window shows its icons at their size against the float area's nearer edge. The window's split tree, its split resizes and its minimized toggle are gone. Trial: the double arrow collapses a floating window's column and expands it, the window keeping its rect. --- crates/ui-panels/src/docking/mod.rs | 2 +- crates/ui-patterns/src/patterns/dock/area.rs | 133 ++++++++++-------- crates/ui-patterns/tests/it/docking/drop.rs | 2 +- .../tests/it/docking/floating_area.rs | 31 ++++ docs/ui-docking.md | 6 +- 5 files changed, 108 insertions(+), 66 deletions(-) diff --git a/crates/ui-panels/src/docking/mod.rs b/crates/ui-panels/src/docking/mod.rs index 2e42fa853..f1ca68ce7 100644 --- a/crates/ui-panels/src/docking/mod.rs +++ b/crates/ui-panels/src/docking/mod.rs @@ -36,7 +36,7 @@ pub use drop::{DockDrag, DockDropTarget, DockDropped, DragUnit, float_drop, reso pub use event::{DockEvent, FloatSpace, HidePanels}; pub use group::{DockGroup, DockGroupOutput, DockGroupStyle, GroupGrip, GroupGripOutput, GroupGripStyle, HeaderHook}; -pub use floating::{FloatingGroup, FloatingGroupOutput, FloatingGroupStyle}; +pub use floating::{FloatingGroup, FloatingGroupOutput, FloatingGroupStyle, WindowColumn}; pub use panels::{DockPanels, request_actions}; #[doc(hidden)] pub use panels::{close_requests, open_requests}; diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 18a9ee759..07964bad7 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -11,9 +11,9 @@ use crate::docking::stack::{StackSection, StackSections, section_heights}; use crate::docking::tree::FrameRules; use crate::docking::{Arrangement, close_requests, cross_window, end_replaced_drags, float_drop, native, open_requests}; use crate::docking::{ - DockColumn, DockCommands, DockConfig, DockDropTarget, DockDropped, DockEvent, DockGroup, DockPanels, DockRoot, DockScene, DockSizes, DockSpot, - DockTargets, DockTo, DockWords, DragUnit, FloatSpace, FloatingGroup, FlyoutResize, GroupAt, GroupDrag, HidePanels, IconicColumn, PanelDrag, - PanelKey, PanelSpec, PanelTitle, SplitArea, actions, dock_states, fit_widths, frame, move_actions, + ColumnBar, DockColumn, DockCommands, DockConfig, DockDropTarget, DockDropped, DockEvent, DockGroup, DockPanels, DockRoot, DockScene, DockSizes, + DockSpot, DockTargets, DockTo, DockWords, DragUnit, FloatSpace, FloatingGroup, FlyoutResize, GroupAt, GroupDrag, HidePanels, IconicColumn, + IconicSizes, PanelDrag, PanelKey, PanelSpec, PanelTitle, SplitArea, WindowColumn, actions, dock_states, fit_widths, frame, move_actions, }; use crate::menu::{GroupItem, MenuWords, PanelMenu, PanelRow}; use crate::runtime::commands::{CommandRef, CommandSet as _, Commands as _, focus_within}; @@ -94,8 +94,8 @@ impl

Outcome for DockAreaOutput

{ /// The docking pattern over a workspace. /// /// - Shape: the docked tree is a `SplitArea`; a dock's columns are `DockColumn`s, or `IconicColumn`s with their -/// flyouts; a group is a `DockGroup`; a floating window is a `FloatingGroup`. The host's `DockPanels` supplies the -/// panels. +/// flyouts; a group is a `DockGroup`; a floating window is a `FloatingGroup` holding one column, shown as a dock's +/// column is, whose bar is the window's title row. The host's `DockPanels` supplies the panels. /// - Edits: a divider drag and every [`Action`] of the pass (menu rows, drags, drops) are written to the workspace /// through its binding, with the panels' [`DockPanels::permissions`] (narrowed when `locked`). The output lists the /// actions the workspace took, divider sizes and window moves included. A given workspace is not written. @@ -283,6 +283,16 @@ struct DockPlan<'p, P> { open: Option

, } +/// Where and how a column shows: its rect; the edge it keeps to, a dock's window edge or the float area's edge a +/// floating window keeps to; where its bar is; the rect its inner edge and flyouts stay within; and the open flyout. +struct ColumnAt

{ + cell: Rect, + edge: DockEdge, + bar: ColumnBar, + within: Rect, + open: Option

, +} + /// What a column reported. struct ColumnWork

{ iconic: Option, @@ -559,7 +569,7 @@ fn show_area( _ => Vec::new(), }; register_bands(&scene, ctx, body.rect, &leaves); - let moved = if floating { pass.windows(ui, body) } else { None }; + let moved = if floating { pass.windows(ui, body, &open) } else { None }; let mut report = pass.report; let label: Arc = Arc::from(body.words::().move_window.as_str()); if let Some((anchor, change)) = moved @@ -890,38 +900,48 @@ impl Pass<'_, P> { let reading = plan.flow.to_physical(plan.rect); let start = plan.edge == DockEdge::Start; let mut cursor = if start { reading.left() } else { reading.right() }; - let name = Label::from(body.words::().panels.as_str().to_owned()); for (column, width) in plan.columns.iter().zip(widths) { let span = if start { (cursor, cursor + width) } else { (cursor - width, cursor) }; cursor = if start { span.1 } else { span.0 }; let cell = plan.flow.to_physical(Rect::from_x_y_ranges(span.0..=span.1, reading.y_range())); let Some(first) = column.groups.first().and_then(|group| group.panels.first()) else { continue }; self.report.placed.push((first.clone(), cell)); - if column.iconic { - let open = plan.open.clone(); - let output = IconicColumn::new(name.clone(), scene.dock, column, Bind::given(open.clone()), &spec) - .edge(plan.edge) - .within(body.rect) - .auto_collapse(scene.auto_collapse) - .show_flyouts_at(ui, cell, |group, at, ui, body| self.group_of(ui, body, group, at)); - self.report.flyout.extend(output.edit.events); - let work = - ColumnWork { iconic: output.iconic, picked: output.picked, resized: Vec::new(), width: output.width, flyout: output.flyout }; - self.column_work(column, work); - } else { - let output = DockColumn::new(name.clone(), scene.dock, column, &spec) - .edge(plan.edge) - .within(body.rect) - .auto_collapse(scene.auto_collapse) - .show_groups_at(ui, cell, |group, rect, ui, body| { - self.group_of(ui, body, group, GroupAt::Show(rect)); - }); - let work = ColumnWork { iconic: output.iconic, picked: output.picked, resized: output.resized, width: output.width, flyout: None }; - self.column_work(column, work); - } + let at = ColumnAt { cell, edge: plan.edge, bar: ColumnBar::Own, within: body.rect, open: plan.open.clone() }; + self.column(ui, body, column, at); } } + /// One column, docked or floating: its icons and their flyouts while it is collapsed, else its stacked groups, + /// each group shown by `group_of`. What the user did on it becomes actions. + fn column(&mut self, ui: &mut Ui, body: &mut BodyCx<'_>, column: &Column

, at: ColumnAt

) { + let scene = self.scene; + let spec = |panel: &P| scene.spec(panel); + let name = Label::from(body.words::().panels.as_str().to_owned()); + let dock = self.dock; + let ColumnAt { cell, edge, bar, within, open } = at; + let work = if column.iconic { + let output = IconicColumn::new(name, dock, column, Bind::given(open), &spec) + .edge(edge) + .bar(bar) + .within(within) + .auto_collapse(scene.auto_collapse) + .show_flyouts_at(ui, cell, |group, at, ui, body| self.group_of(ui, body, group, at)); + self.report.flyout.extend(output.edit.events); + ColumnWork { iconic: output.iconic, picked: output.picked, resized: Vec::new(), width: output.width, flyout: output.flyout } + } else { + let output = DockColumn::new(name, dock, column, &spec) + .edge(edge) + .bar(bar) + .within(within) + .auto_collapse(scene.auto_collapse) + .show_groups_at(ui, cell, |group, rect, ui, body| { + self.group_of(ui, body, group, GroupAt::Show(rect)); + }); + ColumnWork { iconic: output.iconic, picked: output.picked, resized: output.resized, width: output.width, flyout: None } + }; + self.column_work(column, work); + } + /// Turns what a column reported into actions and drags. fn column_work(&mut self, column: &Column

, work: ColumnWork

) { let Some(first) = column.groups.first().and_then(|group| group.panels.first()) else { return }; @@ -955,21 +975,21 @@ impl Pass<'_, P> { } } - /// The floating windows of the pruned layout, each a `FloatingGroup` holding its tree's groups, in an OS window - /// where the config, the platform and its panels allow one. A window takes the drops over it on its own layer, - /// from the spots its groups register in its own registry. Returns the move or resize of a window in the app window - /// this pass, which the area reports as a workspace edit. - fn windows(&mut self, ui: &mut Ui, body: &BodyCx<'_>) -> Option<(P, PlacementChange)> { + /// The floating windows of the pruned layout, each a `FloatingGroup` holding its one column, drawn as a dock + /// column is with the window's title row as the column's bar, in an OS window where the config, the platform and + /// its panels allow one. A window takes the drops over it on its own layer, from the spots its column registers in + /// its own registry. `open` is the open flyout, which a collapsed window's icons share with the docks'. Returns the + /// move or resize of a window in the app window this pass, which the area reports as a workspace edit. + fn windows(&mut self, ui: &mut Ui, body: &BodyCx<'_>, open: &Option

) -> Option<(P, PlacementChange)> { let scene = self.scene; let ctx = ui.ctx().clone(); let policy = |panel: &P| scene.permissions(panel); + let spec_of = |panel: &P| scene.spec(panel); let mut moved = None; for window in &scene.layout.floating { let Some(anchor) = window.panels().next().cloned() else { continue }; - let active = match &window.root { - Node::Tabs { panels, active, .. } => panels.get(*active).cloned().unwrap_or_else(|| anchor.clone()), - _ => anchor.clone(), - }; + // The window's menu acts on the shown panel of its top group. + let active = window.groups().first().and_then(Group::active_panel).cloned().unwrap_or_else(|| anchor.clone()); let specs: Vec = window.panels().map(|panel| scene.spec(panel)).collect(); let rights: Vec = window.panels().map(|panel| scene.permissions(panel)).collect(); let dock = scene.dock.with(("floating", window.id)); @@ -995,10 +1015,17 @@ impl Pass<'_, P> { let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &policy).floated(scene.floated), &active); let mut commands = Vec::new(); let spec = scene.spec(&active); + let edge = WindowColumn::nearer_edge(opening.rect, scene.bounds, scene.rtl); + let shape = if window.column.iconic { + let size = Vec2::new(scene.sizes.width(&window.column, &spec_of), IconicSizes::of(&ctx).icons_height(&window.column)); + WindowColumn::collapsed(edge, size) + } else { + WindowColumn::expanded(edge) + }; let mut group = FloatingGroup::new(spec.label, opening.rect) .limits(scene.spec(&anchor).limits) .sized(Sizing::Fill) - .minimized(window.minimized) + .column(shape) .actions(actions) .window_of(anchor.clone()) .takes_drops(target, &dropped) @@ -1024,23 +1051,10 @@ impl Pass<'_, P> { while let Some((command, _)) = body.take_command::() { commands.push(command); } - let limits = |panel: &P| scene.spec(panel).limits; - let rules = FrameRules::new(&limits); - let name = Label::from(body.words::().panels.as_str().to_owned()); - let tree = Layout::new(Some(window.root.clone()), Vec::new()); - let area = SplitArea::new(name, Bind::given(tree), rules).show_at(ui, body.rect, |ui, split| { - for (leaf, rect) in split.group_frames::

() { - let Some(place) = scene.layout.place(&leaf) else { continue }; - let Some(node) = scene.layout.node_of(&place) else { continue }; - self.leaf(ui, split, node, rect); - } - }); - area.output.edit.events + let at = ColumnAt { cell: body.rect, edge, bar: ColumnBar::Window, within: scene.bounds, open: open.clone() }; + self.column(ui, body, &window.column, at); }); self.dock = area_dock; - if let Some(edited) = shown.inner.as_ref().and_then(EditEvents::value).and_then(|tree| tree.root.as_ref()) { - self.report.actions.extend(split_resizes(&anchor, &window.root, edited)); - } let output = shown.output; self.report.files.extend(output.files); if let Some(dropped) = dropped.into_inner() { @@ -1079,20 +1093,15 @@ impl Pass<'_, P> { for command in commands { self.run(&active, command, Some(body)); } - if output.minimized_toggled { - self.report.actions.push(Action::set_minimized(anchor.clone(), !window.minimized)); + // The title row is the column's bar: its double arrow collapses or expands the column. + if let Some(iconic) = output.iconic { + self.report.actions.push(Action::set_iconic(anchor.clone(), iconic)); } } moved } } -/// The `ResizeWindowSplit` actions that take the splits of the floating window holding `anchor`, whose tree is -/// `from`, to the sizes `to` has. -fn split_resizes(anchor: &P, from: &Node

, to: &Node

) -> Vec> { - split_changes(from, to).into_iter().map(|(path, size)| Action::resize_window_split(anchor.clone(), path, size)).collect() -} - /// The splits whose size `to` changes from `from`, each with its path from the root, where both trees split alike. fn split_changes

(from: &Node

, to: &Node

) -> Vec<(Vec, SplitSize)> { fn walk

(from: &Node

, to: &Node

, path: &mut Vec, out: &mut Vec<(Vec, SplitSize)>) { diff --git a/crates/ui-patterns/tests/it/docking/drop.rs b/crates/ui-patterns/tests/it/docking/drop.rs index c570d08fa..f490138ab 100644 --- a/crates/ui-patterns/tests/it/docking/drop.rs +++ b/crates/ui-patterns/tests/it/docking/drop.rs @@ -18,7 +18,7 @@ const COLUMN_WIDTH: f32 = 200.0; fn layout() -> Layout { let column = Column::new(vec![Group::new(vec![TOP_GROUP, TOP_SECOND_TAB], 0), Group::new(vec![LOWER_GROUP], 0)]).with_width(COLUMN_WIDTH); let dock = Node::dock(DockEdge::Start, vec![column]); - let window = Floating::new(Node::tabs(vec![WINDOW], 0), Rect::from_min_size(at(500.0, 0.0), Vec2::new(200.0, 150.0))); + let window = Floating::single(vec![WINDOW], 0, Rect::from_min_size(at(500.0, 0.0), Vec2::new(200.0, 150.0))); Layout::new(Some(Node::split(Axis::X, SplitSize::FixedFirst(COLUMN_WIDTH), dock, Node::tabs(vec![CANVAS], 0))), vec![window]) } diff --git a/crates/ui-patterns/tests/it/docking/floating_area.rs b/crates/ui-patterns/tests/it/docking/floating_area.rs index f8272007f..0b3b504a8 100644 --- a/crates/ui-patterns/tests/it/docking/floating_area.rs +++ b/crates/ui-patterns/tests/it/docking/floating_area.rs @@ -276,3 +276,34 @@ fn a_floated_panel_fits_its_content_up_to_the_float_height() { assert!((short.width() - group.width()).abs() <= SLACK, "floated {short:?}, docked group {group:?}"); assert!(short.height() < cap - SLACK, "short content floats at its height: {short:?}, cap {cap}"); } + +/// A floating window's title row is its column's bar: its double arrow collapses the column to icons, which show in +/// the window in place of the groups, and expands it again; the window keeps its expanded rect throughout. +#[trial] +fn a_floating_windows_double_arrow_collapses_its_column_to_icons_and_expands_it() { + let mut bed = bed(with_window(Some(Node::tabs(vec![DOCKED], 0))), |_| Permissions::ALL); + let button = |bed: &Bed, name: &str| { + let tree = bed.fixture.tree(); + bed.fixture + .by_role(Role::BUTTON) + .into_iter() + .find(|button| WINDOW_AT.expand(SLACK).contains_rect(button.rect) && craft_ui::testing::access::name(tree, button.node) == Some(name)) + }; + let in_window = |bed: &Bed| bed.fixture.by_role(Role::TAB_PANEL).into_iter().filter(|panel| WINDOW_AT.expand(SLACK).contains_rect(panel.rect)).count(); + assert_eq!(in_window(&bed), 1, "the expanded window shows its group"); + let collapse = button(&bed, "Collapse column to icons").expect("the title row shows the column's double arrow"); + bed.fixture.click(&collapse); + bed.fixture.settle(); + let window = bed.workspace.borrow().layout.floating[0].clone(); + assert!(window.column.iconic, "the window's column collapsed: {:?}", bed.actions.borrow()); + assert_eq!(window.rect, WINDOW_AT, "the window keeps its expanded rect"); + assert_eq!(in_window(&bed), 0, "the collapsed window shows no group"); + let icon = button(&bed, &title(WINDOW)).expect("the collapsed window shows the panel's icon"); + assert!(icon.rect.width() < WINDOW_AT.width() / 2.0, "the window shows as a strip of icons: {:?}", icon.rect); + let expand = button(&bed, "Expand column").expect("the collapsed window's title row shows the double arrow"); + bed.fixture.click(&expand); + bed.fixture.settle(); + let window = bed.workspace.borrow().layout.floating[0].clone(); + assert!(!window.column.iconic && window.rect == WINDOW_AT, "the column expanded at its rect: {window:?}"); + assert_eq!(in_window(&bed), 1, "the expanded window shows its group again"); +} diff --git a/docs/ui-docking.md b/docs/ui-docking.md index b8a5d3193..2f6bdd863 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -21,9 +21,11 @@ A `Workspace` is a saved arrangement: its `layout` and the `hidden` panels with - `Stack`: an accordion; each `StackEntry` keeps its open state and height when other panels move. - `Dock`: the dock on one window edge (`DockEdge`), with its `Column`s from the edge inwards. At most one per side. +A floating window is one `Column` that floats: its groups stacked top to bottom, nothing beside them. Every column, docked or floating, collapses to icons (`Column::iconic`, `Action::SetIconic`) on its own. + The tree is in reading order: a split's first child is its start (or top) child. Under right-to-left the renderer maps rects with `Flow::to_physical`. -Edits are `Action`s: `Move`, `Float`, `Close`, `Activate`, `Open`, `OpenAt`, `MoveFloating`, `ResizeSplit`, `ResizeWindowSplit` and the rest. `Workspace::apply` and `Workspace::apply_all` apply them against each panel's `Permissions` and the lock, and refuse what the rules forbid with a `DockError`. `Permissions::ALL` allows everything. `Permissions::PROTECTED` is a document canvas: it stays docked and open, and takes neither tabs nor side splits. +Edits are `Action`s: `Move`, `Float`, `Close`, `Activate`, `Open`, `OpenAt`, `MoveFloating`, `ResizeSplit`, `SetIconic` and the rest. `Workspace::apply` and `Workspace::apply_all` apply them against each panel's `Permissions` and the lock, and refuse what the rules forbid with a `DockError`. `Permissions::ALL` allows everything. `Permissions::PROTECTED` is a document canvas: it stays docked and open, and takes neither tabs nor side splits. To load a saved workspace: @@ -114,7 +116,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords ## Floating and native windows -A floating window is a `Floating` in the layout: its `rect` in logical points in the app's viewport, and `native` and `monitor` while it is an OS window. `FloatingGroup` shows it. With `DockConfig::native_windows` (on by default), every floating window opens in its own OS window (`docking::native`) where the window host opens OS windows and reports where they are (`WindowHost::positions_reported`; not on Wayland); a window never shown native yet opens over its place in the main window. Elsewhere, and for a panel with `allow_native` off, the window stays inside the main window. The OS close of a native window is its Close action: the window closes when every panel in it may close. Dragging a native window by its title row moves the whole window and docks it where it is released over a group of the main window, as a floating window inside the main window does: the window host runs that move (`runtime::windows::keeps_app_drag`). On macOS the row's press hands the move to the OS, the app follows the system pointer and button (`Caps::OS_MOVES_TRACKED`), and a press that ends within the click distance is a click, which docks nothing; elsewhere the app moves the window, and Escape puts it back. The app sends an OS window its place only when the app changes it (an undo, a reloaded layout); the OS's own moves and resizes are recorded and never sent back. `window_kind` says whether an OS window is a document or a tool window. A tool window's title row is its only title bar, whatever frame the main window has (`craft_window::policy::tool_frame`). +A floating window is a `Floating` in the layout: its one `column`, its `rect` in logical points in the app's viewport, and `native` and `monitor` while it is an OS window. `FloatingGroup` shows it, with the column inside drawn as a dock column is (`ColumnBar::Window`): the window's title row is the column's bar, whose double arrow, like a double click on the row, collapses the column to icons. A collapsed window shows its icons against the float area's edge nearer it, and keeps its expanded size for when it expands. With `DockConfig::native_windows` (on by default), every floating window opens in its own OS window (`docking::native`) where the window host opens OS windows and reports where they are (`WindowHost::positions_reported`; not on Wayland); a window never shown native yet opens over its place in the main window. Elsewhere, and for a panel with `allow_native` off, the window stays inside the main window. The OS close of a native window is its Close action: the window closes when every panel in it may close. Dragging a native window by its title row moves the whole window and docks it where it is released over a group of the main window, as a floating window inside the main window does: the window host runs that move (`runtime::windows::keeps_app_drag`). On macOS the row's press hands the move to the OS, the app follows the system pointer and button (`Caps::OS_MOVES_TRACKED`), and a press that ends within the click distance is a click, which docks nothing; elsewhere the app moves the window, and Escape puts it back. The app sends an OS window its place only when the app changes it (an undo, a reloaded layout); the OS's own moves and resizes are recorded and never sent back. `window_kind` says whether an OS window is a document or a tool window. A tool window's title row is its only title bar, whatever frame the main window has (`craft_window::policy::tool_frame`). A panel or group floated out of the dock (a drag, the Float command, a tab torn out of the window) opens at the width it had docked and at the height its group measures at in a floating window's room (`Proposal::Size`), at most `size.float.height`: content that fills its body opens at that height, other content at its own. A column opens at its docked size, at most that height. The area measures once, where the float starts: for a drag in the pass it starts, which adds the size to the drag's payload (`runtime::drag::amend`). A panel's own `PanelSpec` float size wins, and a window that already floats keeps its size.