From ddd2e23f89aecf5e7a645843fd5219eef0d1681b Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 19:45:04 +0000 Subject: [PATCH] Collapsed floating windows resize their width A collapsed dock window's sides resize its width, and only its width, within the bounds of a docked collapsed column (DockSizes::iconic_bounds, the one rule both use), on macOS by AppKit and elsewhere by the window's own grips. FloatingGroupOutput::collapsed_width reports the width, which the area keeps as the column's iconic width through the docked column's own path (Action::ResizeIconic); names show from IconicSizes::labels as in a docked column. The height stays the icons', the expanded rect keeps its size and the window keeps its edge. The column in a window has no inner-edge divider: the window's sides size it, as for an expanded column. --- .../ui-contract/src/contract/body/window.rs | 2 +- crates/ui-panels/src/docking/floating.rs | 58 +++++++++++----- .../ui-panels/src/docking/floating/stories.rs | 21 ++++-- crates/ui-panels/src/docking/iconic.rs | 42 +++++++----- crates/ui-panels/src/docking/targets.rs | 13 ++-- crates/ui-patterns/src/patterns/dock/area.rs | 17 +++-- .../tests/it/docking/floating_area.rs | 66 +++++++++++++++++-- crates/ui-patterns/tests/it/docking/native.rs | 51 ++++++++++++++ docs/ui-docking.md | 2 +- 9 files changed, 221 insertions(+), 51 deletions(-) diff --git a/crates/ui-contract/src/contract/body/window.rs b/crates/ui-contract/src/contract/body/window.rs index d6ac190c4..7976228fe 100644 --- a/crates/ui-contract/src/contract/body/window.rs +++ b/crates/ui-contract/src/contract/body/window.rs @@ -51,7 +51,7 @@ impl WindowParts { /// The band a layer keeps clear at its top for its top grip, so that grip never lies over the header: the grip's /// width ([`grip_band`]) on a layer whose header is on a line of its own and whose top grip or a top corner's stands, -/// or that the user moves: a floating window keeps the band while it cannot be resized (collapsed, minimized), so its +/// or that the user moves: a floating window keeps the band while it has no top grip (collapsed, minimized), so its /// header stays where it was. None elsewhere, nor on a layer whose band moves the window below it. The regions start /// below the band, or below the padding where that is deeper. An OS window keeps none: its grips, the platform's or /// the app's, lie over its title bar as an OS title bar's resize edge does. diff --git a/crates/ui-panels/src/docking/floating.rs b/crates/ui-panels/src/docking/floating.rs index 034daee21..952ef2d55 100644 --- a/crates/ui-panels/src/docking/floating.rs +++ b/crates/ui-panels/src/docking/floating.rs @@ -12,7 +12,7 @@ use super::drop::{DragUnit, start_group_drag}; use super::{DockDropTarget, DockDropped, DockWords, GroupDrag, PanelDrag, PanelKey, native}; use crate::contract::BodyCx; use crate::contract::SizeLimits; -use crate::contract::overlay::{PlacementChange, PlacementKind, Popup}; +use crate::contract::overlay::{PlacementChange, PlacementKind, Popup, ResizeEdges}; use crate::contract::{ Access, Bind, BindMut, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderEdge, HeaderParts, HeaderRegion, Inner, MeasureCx, Mount, NoValue, OsFiles, Outcome, Overlay, Pad, PaintUi, PartsCx, Pointer as _, Props as _, Role, Show as _, ShowContainer as _, Sizing, @@ -61,6 +61,9 @@ pub struct WindowColumn { pub edge: DockEdge, /// The size of the collapsed column under the title row; `None` while the column is expanded. pub collapsed: Option, + /// The least and most width the sides of a collapsed column's window resize it to + /// ([`DockSizes::iconic_bounds`](super::DockSizes::iconic_bounds)); unbounded while the column is expanded. + pub widths: (f32, f32), /// The size of an expanded column whose content sets it (a column with steps) under the title row; `None` for a /// column the rect sizes. pub fitted: Option, @@ -71,19 +74,20 @@ pub struct WindowColumn { impl WindowColumn { /// An expanded column that keeps to `edge`. pub fn expanded(edge: DockEdge) -> Self { - WindowColumn { edge, collapsed: None, fitted: None, arrow: ColumnArrow::Collapse } + WindowColumn { edge, collapsed: None, widths: UNBOUNDED, fitted: None, arrow: ColumnArrow::Collapse } } - /// A column collapsed to icons, `size` under the title row, that keeps to `edge`. - pub fn collapsed(edge: DockEdge, size: Vec2) -> Self { - WindowColumn { edge, collapsed: Some(size), fitted: None, arrow: ColumnArrow::Collapse } + /// A column collapsed to icons, `size` under the title row, that keeps to `edge`. The window's sides resize its + /// width within `widths`, as a docked collapsed column's inner edge does; its height stays `size`'s. + pub fn collapsed(edge: DockEdge, size: Vec2, widths: (f32, f32)) -> Self { + WindowColumn { edge, collapsed: Some(size), widths, fitted: None, arrow: ColumnArrow::Collapse } } /// An expanded column whose content is `size` under the title row, that keeps to `edge`. The window shows at /// that size at its rect's place; a resize the user makes is reported for the host to turn into the column's /// steps, and a move keeps the rect's size. pub fn fitted(edge: DockEdge, size: Vec2) -> Self { - WindowColumn { edge, collapsed: None, fitted: Some(size), arrow: ColumnArrow::Collapse } + WindowColumn { edge, collapsed: None, widths: UNBOUNDED, fitted: Some(size), arrow: ColumnArrow::Collapse } } /// The column with the double arrow `arrow` ([`ColumnArrow::of`]). @@ -102,9 +106,12 @@ impl WindowColumn { } /// The rect a window that keeps `rect` keeps when it shows at `shown`: while collapsed, `rect` moved with the - /// collapsed column ([`Self::shown`]), so it keeps its expanded size; while expanded, `shown`. + /// collapsed column ([`Self::shown`]) so that the column's side on the edge the window keeps to stays on that side + /// of `rect`, whatever width the column shows at; `rect` keeps its expanded size. While expanded, `shown`. pub fn kept(self, shown: Rect, rect: Rect, chrome: f32, rtl: bool) -> Rect { - self.shown(rect, chrome, rtl).map_or(shown, |at| rect.translate(shown.min - at.min)) + let Some(at) = self.shown(rect, chrome, rtl) else { return shown }; + let dx = if at_left(self.edge, rtl) { shown.left() - at.left() } else { shown.right() - at.right() }; + rect.translate(Vec2::new(dx, shown.top() - at.top())) } /// The edge of `bounds`, in reading order, nearer the window at `rect`: the start edge when the window's centre is @@ -134,6 +141,9 @@ impl WindowColumn { } } +/// The widths of a column that is not collapsed: its window's limits are the panels'. +const UNBOUNDED: (f32, f32) = (0.0, f32::INFINITY); + /// Whether `edge`, in reading order, is the left one of the screen. fn at_left(edge: DockEdge, rtl: bool) -> bool { (edge == DockEdge::Start) != rtl @@ -157,6 +167,9 @@ pub struct FloatingGroupOutput { /// The user asked to collapse the window's column to icons (`true`) or expand it (`false`): a click on the double /// arrow, or a double click on the title band. Only a group with a [`WindowColumn`] reports it. pub iconic: Option, + /// The width the user gave the collapsed column of the window this pass, by a side of the window or the keyboard + /// Size mode: the host keeps it as the column's iconic width. The rect in `placed` stays the expanded one. + pub collapsed_width: Option, /// The files dropped on the group's window that no target there took. pub files: Vec, } @@ -182,7 +195,8 @@ impl Outcome for FloatingGroupOutput { /// - Column: a dock window holds one column ([`column`](FloatingGroup::column)); its title row is the column's bar, /// with the double arrow at the end the window keeps to. While the column is collapsed the group shows at the /// collapsed size against that edge of the rect, its title row shows no actions (the band and the double arrow; -/// a context request on the band opens the menu), the edges do not resize, and a move keeps the rect's size. A +/// a context request on the band opens the menu), its sides resize its width within the column's widths (reported +/// in [`FloatingGroupOutput::collapsed_width`]) while its height stays the icons', and the rect keeps its size. A /// column its content sizes ([`WindowColumn::fitted`]) shows at that size at the rect's place; its resizes are /// reported as the user makes them, and in an OS window the app runs them, so the window takes only the size the /// host gives it. @@ -240,6 +254,8 @@ pub struct FloatingGroup<'a> { chrome: f32, rtl: bool, placed: Option, + /// The width a resize gave the collapsed column this pass. + collapsed_width: Option, /// Starts the window-unit drag; set by `window_of`. start_drag: Option>, /// Takes the drops released on the group, on the group's own layer. @@ -285,6 +301,7 @@ impl<'a> FloatingGroup<'a> { chrome: 0.0, rtl: false, placed: None, + collapsed_width: None, start_drag: None, take_drop: None, moving: false, @@ -350,11 +367,13 @@ impl<'a> FloatingGroup<'a> { fn mount(&self) -> Mount { // The frame's limits are the body's with the chrome on top. let frame = self.limits.around(Vec2::new(0.0, self.chrome)); - let collapsed = self.collapsed_rect(); - let mut overlay = - Overlay::floating().movable(true).resizable(!self.minimized && collapsed.is_none()).opacity(self.opacity).body_scroll(false); - overlay = if let Some(shown) = collapsed { - overlay.placed(shown).size_limits(SizeLimits::new(shown.size(), shown.size())) + let collapsed = self.collapsed_rect().zip(self.column.map(|column| column.widths)); + let mut overlay = Overlay::floating().movable(true).resizable(!self.minimized).opacity(self.opacity).body_scroll(false); + overlay = if let Some((shown, (least, most))) = collapsed { + // The sides resize a collapsed column's width; its height is its icons'. + let height = shown.height(); + let edges = if self.minimized { ResizeEdges::NONE } else { ResizeEdges::LEFT.union(ResizeEdges::RIGHT) }; + overlay.placed(shown).resize_edges(edges).size_limits(SizeLimits::new(Vec2::new(least, height), Vec2::new(most.max(least), height))) } else if let Some(size) = self.column.and_then(|column| column.fitted) { // The host turns a resize into the column's steps, and the window takes the size they make. overlay.placed(Rect::from_min_size(self.rect.min, size + Vec2::new(0.0, self.chrome))).sized_by_caller() @@ -460,6 +479,7 @@ impl Component for FloatingGroup<'_> { action: self.taken, minimized_toggled: self.toggled && self.column.is_none(), iconic, + collapsed_width: self.collapsed_width, files: self.files, }; native::raise(&cx.core.ctx, &output); @@ -505,7 +525,15 @@ impl Container for FloatingGroup<'_> { let mut change = *change; let fitted = self.column.is_some_and(|column| column.fitted.is_some()); if let Some(column) = self.column.filter(|column| column.collapsed.is_some()) { - // The collapsed window moves; the rect keeps its expanded size. + // A resize of the collapsed window sets the column's width; the rect keeps its expanded size. + let resized = match change.kind { + PlacementKind::Size(_) => true, + PlacementKind::Keyboard => self.collapsed_rect().is_some_and(|shown| change.rect.width() != shown.width()), + _ => false, + }; + if resized { + self.collapsed_width = Some(change.rect.width()); + } change.rect = column.kept(change.rect, self.rect, self.chrome, self.rtl); } else if (fitted || self.sized == Sizing::Content) && change.kind == PlacementKind::Move { // A window its content sizes moves (a cancel too, which reports the rect from before the gesture); the diff --git a/crates/ui-panels/src/docking/floating/stories.rs b/crates/ui-panels/src/docking/floating/stories.rs index 65f0cd780..24a6d07c8 100644 --- a/crates/ui-panels/src/docking/floating/stories.rs +++ b/crates/ui-panels/src/docking/floating/stories.rs @@ -14,10 +14,13 @@ const START: Rect = Rect { min: Pos2::new(40.0, 40.0), max: Pos2::new(280.0, 220 /// The icons a collapsed story column shows: three panels. const ICON_CELLS: f32 = 3.0; -/// The size of a collapsed column of `ICON_CELLS` icon cells. -fn icon_strip(ui: &Ui) -> Vec2 { +/// A collapsed column of `ICON_CELLS` icon cells, `width` wide when the user resized it, else the rail's width: it +/// resizes from the rail's width up to the width of the expanded story window. +fn icon_strip(ui: &Ui, edge: DockEdge, width: Option) -> WindowColumn { let sizes = IconicSizes::of(ui.ctx()); - Vec2::new(sizes.cell, sizes.cell * ICON_CELLS) + let widths = (sizes.column.iconic_least, START.width()); + let width = width.unwrap_or(widths.0).clamp(widths.0, widths.1); + WindowColumn::collapsed(edge, Vec2::new(width, sizes.cell * ICON_CELLS), widths) } #[story(FloatingGroup<'static>, covers = [Default], drive = Drive::Never)] @@ -42,7 +45,8 @@ fn floating_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { fn floating_dock_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let rect = *data.value("rect", START); let collapsed = *data.value("collapsed", false); - let column = if collapsed { WindowColumn::collapsed(DockEdge::Start, icon_strip(ui)) } else { WindowColumn::expanded(DockEdge::Start) }; + let width = *data.value("width", None::); + let column = if collapsed { icon_strip(ui, DockEdge::Start, width) } else { WindowColumn::expanded(DockEdge::Start) }; let shown = FloatingGroup::new("Layers", rect).column(column).sized(crate::contract::Sizing::Fill).show_group(ui, |ui, _| { Button::new(if collapsed { "L" } else { "Add layer" }).show(ui); }); @@ -52,6 +56,9 @@ fn floating_dock_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { if let Some(iconic) = shown.output.iconic { *data.value("collapsed", false) = iconic; } + if let Some(width) = shown.output.collapsed_width { + *data.value("width", None::) = Some(width); + } shown.output.into() } @@ -59,12 +66,16 @@ fn floating_dock_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { #[story(FloatingGroup<'static>, covers = [Default], drive = Drive::Never)] fn floating_collapsed_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let rect = *data.value("rect", START); - let column = WindowColumn::collapsed(DockEdge::End, icon_strip(ui)); + let width = *data.value("width", None::); + let column = icon_strip(ui, DockEdge::End, width); let shown = FloatingGroup::new("Layers", rect).column(column).sized(crate::contract::Sizing::Fill).show_group(ui, |ui, _| { Button::new("L").show(ui); }); if let Some(change) = shown.output.placed { *data.value("rect", START) = change.rect; } + if let Some(width) = shown.output.collapsed_width { + *data.value("width", None::) = Some(width); + } shown.output.into() } diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index b52dffc8f..d08285730 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -102,7 +102,8 @@ pub struct IconicColumnOutput

{ pub iconic: Option, /// The dock row the user picked in the column menu. pub picked: Option, - /// The width the user gave the iconic column on its inner edge this pass. + /// The width the user gave a docked iconic column on its inner edge this pass. A floating window's sides set the + /// width of the column it holds (`FloatingGroupOutput::collapsed_width`). pub width: Option, /// The size the user gave the open flyout, with the top edge's offset from the icons when it moved. pub flyout: Option>, @@ -179,8 +180,8 @@ pub struct IconicColumnStyle { /// The user resizes it by its top and bottom edges and the edge away from the column; each step comes back in /// [`IconicColumnOutput::flyout`], which the host keeps in the group (`flyout_width`, `height`, `flyout_offset`). /// -/// In a floating window ([`ColumnBar::Window`]) the window's title row is the column's bar: the column shows its -/// icons under it and keeps the divider of its inner edge, which sets its width, and registers no edge bands. +/// In a floating window ([`ColumnBar::Window`]) the window's title row is the column's bar and the window's sides set +/// its width: the column shows its icons under it, with no divider on its inner edge, and registers no edge bands. #[derive(crate::contract::Component, crate::contract::Props)] #[component(container, overlay, probe(IconicColumn<'static, u8>))] pub struct IconicColumn<'a, P: Value + Hash + 'static> { @@ -309,8 +310,8 @@ impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> { /// The panels of the column in order, each with its group. /// The divider on the column's inner edge: the width runs from the rail to the width the column expands to. fn edge_divider(&self, rect: Rect, sizes: &DockSizes) -> Divider { - let least = sizes.iconic_least; - let most = sizes.expanded_width(self.column, self.spec).max(least).min((self.within.width() - sizes.least_pane).max(rect.width())); + let (least, most) = sizes.iconic_bounds(self.column, self.spec); + let most = most.min((self.within.width() - sizes.least_pane).max(rect.width())); Divider::column_edge(rect, self.edge, (least, most), sizes.reach) } @@ -474,7 +475,9 @@ impl Component for IconicColumn<'_, P> { .drag_cursor(CursorIcon::Grabbing) .pointer_only("Move Panel To in the panel menu moves the group's panels"); } - divider::declare(cx, rect, EDGE, 0, &self.edge_divider(rect, &sizes.column)); + if self.bar == ColumnBar::Own { + divider::declare(cx, rect, EDGE, 0, &self.edge_divider(rect, &sizes.column)); + } self.laid = Some(plan); } @@ -509,12 +512,14 @@ impl Component for IconicColumn<'_, P> { began = true; } } - let edge = self.edge_divider(rect, &sizes.column); - if let Some(Drag::To(coord)) = divider::pointer(cx, EDGE, 0, &edge) { - self.move_edge(rect, &edge, coord); - } - if let Some((_, coord)) = divider::keys(cx, EDGE, &[(0, edge)], sizes.column.step, sizes.column.jump) { - self.move_edge(rect, &edge, coord); + if self.bar == ColumnBar::Own { + let edge = self.edge_divider(rect, &sizes.column); + if let Some(Drag::To(coord)) = divider::pointer(cx, EDGE, 0, &edge) { + self.move_edge(rect, &edge, coord); + } + if let Some((_, coord)) = divider::keys(cx, EDGE, &[(0, edge)], sizes.column.step, sizes.column.jump) { + self.move_edge(rect, &edge, coord); + } } let handles: Vec<_> = (0..flat.len()).map(|at| popup.at(at)).collect(); // A toggle of an icon (click, Enter, Alt+Down) changed a popup this pass: the user chose. Otherwise the @@ -582,10 +587,13 @@ impl Component for IconicColumn<'_, P> { let bar = Rect::from_center_size(strip.center(), Vec2::new(style.grip_length.min(strip.width()), style.grip_thickness)); ui.draw().fill(&PaintShape::Rect(bar, style.grip_radius), ink); } - // The edge's line lies on the column's inner edge; its handle stays inside the column. - let (rect, edge) = (cx.rect, self.edge_divider(cx.rect, &cx.style.sizes.column)); - let x = if cx.flow.is_rtl() { rect.right() - (edge.at - rect.left()) } else { edge.at }; - ui.face(EDGE.at(0), Splitter::new(Axis::X).boundary(x)); + // The edge's line lies on the column's inner edge; its handle stays inside the column. A floating window's + // edges are the window's. + if self.bar == ColumnBar::Own { + let (rect, edge) = (cx.rect, self.edge_divider(cx.rect, &cx.style.sizes.column)); + let x = if cx.flow.is_rtl() { rect.right() - (edge.at - rect.left()) } else { edge.at }; + ui.face(EDGE.at(0), Splitter::new(Axis::X).boundary(x)); + } } fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) { @@ -601,8 +609,8 @@ impl Component for IconicColumn<'_, P> { let name = words.move_group.fill(&[("name", (self.spec)(shown).label.as_str())]); access.node(GRIP.at(*group as u64), Role::BUTTON).name = Name::Text(name); } - divider::describe(access, EDGE, 0, &self.edge_divider(cx.rect, &sizes.column), words.resize.as_str(), sizes.column.step); if self.bar == ColumnBar::Own { + divider::describe(access, EDGE, 0, &self.edge_divider(cx.rect, &sizes.column), words.resize.as_str(), sizes.column.step); describe_chevron(access, &ColumnArrow::Collapse.name(&words, false)); } } diff --git a/crates/ui-panels/src/docking/targets.rs b/crates/ui-panels/src/docking/targets.rs index c04fdc4d7..bc50de89a 100644 --- a/crates/ui-panels/src/docking/targets.rs +++ b/crates/ui-panels/src/docking/targets.rs @@ -129,13 +129,18 @@ impl DockSizes { column.width.unwrap_or(self.column).clamp(lo, hi) } + /// The width bounds of a column collapsed to icons, docked or floating: the rail width up to the width it expands + /// to. A docked column's inner edge and a floating window's sides resize it within them. + pub fn iconic_bounds

(&self, column: &Column

, spec: &dyn Fn(&P) -> PanelSpec) -> (f32, f32) { + (self.iconic_least, self.expanded_width(column, spec).max(self.iconic_least)) + } + /// The bounds [`width`](Self::width) keeps a column in: an expanded column's [`width_bounds`](Self::width_bounds); - /// a stepped one's width at one step up to its width at all its grid's columns; an iconic column's rail width up - /// to the width it expands to. + /// a stepped one's width at one step up to its width at all its grid's columns; an iconic column's + /// [`iconic_bounds`](Self::iconic_bounds). pub fn shown_bounds

(&self, column: &Column

, spec: &dyn Fn(&P) -> PanelSpec) -> (f32, f32) { if column.iconic { - // Widening an iconic column stops at the width it expands to. - (self.iconic_least, self.expanded_width(column, spec).max(self.iconic_least)) + self.iconic_bounds(column, spec) } else if let Some((grid, _)) = stepped(column, spec) { (grid.width(1), grid.width(grid.most)) } else { diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 739891bae..d0b8680d6 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -1281,7 +1281,9 @@ impl Pass<'_, P> { /// double arrow sits at that end, and its collapsed column shows against that edge of its rect. A move or resize /// keeps the edge the window had when it began, so nothing jumps while the window crosses the middle. A collapsed /// window's move ends at the edge nearer the strip where it was dropped, with the rect that shows the strip there - /// ([`WindowColumn::dropped`]); an expanded window's move leaves its edge to its rect. An OS window is measured + /// ([`WindowColumn::dropped`]); an expanded window's move leaves its edge to its rect. A collapsed window's sides + /// resize its column's width within [`DockSizes::iconic_bounds`] (`Action::ResizeIconic`, as a docked collapsed + /// column's inner edge does), and the window keeps its edge and its expanded rect's size. An OS window is measured /// where it would sit in the app window ([`native::in_app`]), and the end of each of its moves and resizes records /// that rect and edge; its placement keeps its expanded rect while its column is collapsed ([`WindowColumn::kept`]). /// @@ -1342,7 +1344,7 @@ impl Pass<'_, P> { let width = scene.sizes.expanded_width(&window.column, &spec_of); 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) + WindowColumn::collapsed(edge, size, scene.sizes.iconic_bounds(&window.column, &spec_of)) } else if let Some(content) = self.stepped_height(ui, body, &window.column, width, true) { WindowColumn::fitted(edge, Vec2::new(width, content)) } else { @@ -1412,7 +1414,9 @@ impl Pass<'_, P> { && let Some(change) = output.placed.filter(|change| change.phase == GesturePhase::Commit) && let Some(rect) = native::in_app(&ctx, change.rect) { - let (rect, keeps) = shape.dropped(rect, scene.bounds, scene.rtl); + // A resize of a collapsed window keeps its edge; a move ends where its strip was dropped. + let (rect, keeps) = + if output.collapsed_width.is_some() { (rect, Some(edge)) } else { shape.dropped(rect, scene.bounds, scene.rtl) }; kept.edge = keeps.unwrap_or(kept.edge); self.report.actions.push(Action::move_floating_with_edge(anchor.clone(), rect, keeps)); } @@ -1422,7 +1426,7 @@ impl Pass<'_, P> { } else if let Some(mut change) = output.placed { // A collapsed window keeps the edge its move began with until the move ends where its strip was dropped. let mut keeps = shape.collapsed.map(|_| edge); - if change.phase == GesturePhase::Commit { + if change.phase == GesturePhase::Commit && output.collapsed_width.is_none() { (change.rect, keeps) = shape.dropped(change.rect, scene.bounds, scene.rtl); } // The window keeps the place of its steps; its size is the steps' own, whatever the rect keeps. @@ -1434,6 +1438,11 @@ impl Pass<'_, P> { } moved = Some((anchor.clone(), change, keeps)); } + // The sides of a collapsed window set its column's width, as a docked collapsed column's inner edge does. + if let Some(width) = output.collapsed_width { + let work = ColumnWork { iconic: None, picked: None, resized: Vec::new(), width: Some(width), flyout: None }; + self.column_work(&window.column, work); + } // The OS close of a native window arrives here as well, also where the title row offers no Close. if output.action == Some(HeaderAction::Close) && rights.iter().all(|rights| rights.closable) { self.report.actions.push(Action::close_window(anchor.clone())); diff --git a/crates/ui-patterns/tests/it/docking/floating_area.rs b/crates/ui-patterns/tests/it/docking/floating_area.rs index 11921e944..7fad2cfbe 100644 --- a/crates/ui-patterns/tests/it/docking/floating_area.rs +++ b/crates/ui-patterns/tests/it/docking/floating_area.rs @@ -4,11 +4,12 @@ use craft_behavior::Axis; use craft_behavior::dock::{Action, Column, DockEdge, Floating, Group, Layout, Node, Permissions, SplitSize, Workspace}; use craft_ui::contract::{Bind, BodyCx, Role, Show as _, ShowContainer as _}; use craft_ui::display::Text; -use craft_ui::docking::{DockConfig, DockPanels, GroupDrag, PanelSpec, request_actions}; +use craft_ui::docking::{DockConfig, DockPanels, GroupDrag, IconicSizes, PanelSpec, request_actions}; use craft_ui::layout_components::Stack; use craft_ui::patterns::dock::DockArea; use craft_ui::runtime::drag::{self, DropMark}; use craft_ui::testing::pointer::{moved, press, release, secondary}; +use craft_ui::testing::snapshot::layer_rects; use craft_ui::testing::{Fixture, trial}; use egui::{Modifiers, Pos2, Rect, Ui, Vec2}; use std::cell::{Cell, RefCell}; @@ -428,8 +429,7 @@ fn a_collapsed_window_dragged_across_the_middle_keeps_its_strip_under_the_pointe let mut bed = bed(collapsed_at(WINDOW_AT), |_| Permissions::ALL); let icon = button_rect(&bed, &title(WINDOW)).expect("the collapsed window shows its icon"); let by = Vec2::new(middle.map_or(-250.0, |x: f32| x - icon.center().x), 0.0); - // The title row's band, clear of the double arrow at the end the window keeps to. - let band = Pos2::new(icon.left() + 4.0, window_title().y); + let band = strip_band(icon); bed.fixture.drag_hold_at(band, by); let held = button_rect(&bed, &title(WINDOW)).expect("the icon shows while the window moves"); assert!((held.left() - (icon.left() + by.x)).abs() <= SLACK, "by {by:?}: the strip follows the pointer: {icon:?}, then {held:?}"); @@ -471,6 +471,64 @@ fn an_icon_floated_in_the_middle_band_lands_collapsed_under_the_pointer() { assert!((settled.left() - floated.left()).abs() <= SLACK, "the strip stays: {floated:?}, then {settled:?}"); } +/// The rect of the collapsed window's layer: the smallest layer around its icon. +fn strip_window(bed: &Bed) -> Rect { + let icon = button_rect(bed, &title(WINDOW)).expect("the collapsed window shows its icon"); + let layers = layer_rects(bed.fixture.ctx()).into_iter().filter(|rect| rect.contains(icon.center())); + layers.min_by(|a, b| a.area().total_cmp(&b.area())).expect("the window's layer holds its icon") +} + +/// A point of a collapsed window's title band: the band's start, clear of the side grip (`size.handle.sm` deep) and +/// of the double arrow at the end the window keeps to. +fn strip_band(icon: Rect) -> Pos2 { + Pos2::new(icon.left() + 10.0, window_title().y) +} + +/// A collapsed window's sides resize its width, and only its width, as a docked collapsed column's inner edge does: +/// the column's iconic width follows, names show beside the icons from the docked column's labels width on, the +/// column stays as tall as its icons, and the expanded rect keeps its size. The width stays across expanding and +/// collapsing again. +#[trial] +fn a_collapsed_windows_sides_resize_its_width_and_show_names_from_the_docked_columns_step() { + let mut bed = bed(collapsed_at(WINDOW_AT), |_| Permissions::ALL); + let sizes = IconicSizes::of(bed.fixture.ctx()); + let height = sizes.icons_height(&bed.workspace.borrow().layout.floating[0].column); + let named = |bed: &Bed| bed.fixture.texts().iter().any(|run| run.text == title(WINDOW)); + let height = height + bed.chrome.get(); + let strip = strip_window(&bed); + assert!(!named(&bed), "a rail-wide strip shows no names"); + assert!((strip.height() - height).abs() <= SLACK, "the window is as tall as its icons and its chrome: {strip:?}, {height}"); + assert!((strip.right() - WINDOW_AT.right()).abs() <= SLACK, "the strip keeps to the end edge: {strip:?}"); + // The start side faces the room; a press just inside it holds the window's grip. + let mut side = Pos2::new(strip.left() + 2.0, strip.center().y); + for width in [sizes.labels - 10.0, sizes.labels + 20.0] { + let by = Vec2::new(strip_window(&bed).width() - width, 0.0); + press_and_move(&mut bed.fixture, side, by); + bed.fixture.frame(vec![release(side + by)]); + bed.fixture.settle(); + side += by; + let window = bed.workspace.borrow().layout.floating[0].clone(); + let shown = strip_window(&bed); + let kept = window.column.iconic_width; + assert!(window.column.iconic && kept.is_some_and(|kept| (kept - width).abs() <= SLACK), "{width}: the column keeps the width: {window:?}"); + assert!((shown.width() - width).abs() <= SLACK, "{width}: the strip shows at it: {shown:?}"); + assert!((shown.height() - height).abs() <= SLACK, "{width}: the height stays its icons' and its chrome's: {shown:?}"); + assert!( + (window.rect.min - WINDOW_AT.min).length() <= SLACK && window.rect.size() == WINDOW_AT.size(), + "{width}: the expanded rect stays: {window:?}" + ); + assert_eq!(named(&bed), width >= sizes.labels, "{width}: names show from the labels width ({}) on", sizes.labels); + } + let resized = strip_window(&bed); + for iconic in [false, true] { + bed.workspace.borrow_mut().apply(Action::set_iconic(WINDOW, iconic), false, |_| Permissions::ALL).expect("the column toggles"); + bed.fixture.settle(); + } + let again = strip_window(&bed); + assert!((again.width() - resized.width()).abs() <= SLACK, "collapsed again, the strip keeps its width: {resized:?}, then {again:?}"); + assert_eq!(bed.workspace.borrow().layout.floating[0].rect, WINDOW_AT, "the expanded rect is unchanged"); +} + /// A floating collapsed column opens its flyouts towards the room of the float area, away from the edge it keeps to. #[trial] fn a_floating_collapsed_columns_flyout_opens_towards_the_room() { @@ -496,7 +554,7 @@ fn a_double_click_on_a_floating_windows_band_collapses_and_expands_its_column() assert!(window.column.iconic, "the band's double click collapsed the column: {:?}", bed.actions.borrow()); assert!(window.groups().iter().all(|group| !group.minimized), "no group minimized"); let icon = button_rect(&bed, &title(WINDOW)).expect("the collapsed window shows its icon"); - let band = Pos2::new(icon.left() + 4.0, window_title().y); + let band = strip_band(icon); bed.fixture.click_at(band).click_at(band).settle(); assert!(!bed.workspace.borrow().layout.floating[0].column.iconic, "a second double click expanded it: {:?}", bed.actions.borrow()); } diff --git a/crates/ui-patterns/tests/it/docking/native.rs b/crates/ui-patterns/tests/it/docking/native.rs index 5e25fb2f1..681d42e1e 100644 --- a/crates/ui-patterns/tests/it/docking/native.rs +++ b/crates/ui-patterns/tests/it/docking/native.rs @@ -653,6 +653,57 @@ fn a_native_palette_collapsed_moved_and_expanded_comes_back_at_its_size() { assert!(max.is_none_or(|max| max.x >= expanded.x && max.y >= expanded.y), "the OS lets it take that size: max {max:?}"); } +/// On macOS a native palette collapsed to icons is a window AppKit resizes, in its width only: it opens resizable with +/// its height fixed to the strip's, the app stands no grips of its own at its sides, and a width the OS gives it is the +/// column's iconic width while the model keeps the expanded size; the app sends no size back. +#[trial] +fn a_collapsed_native_palette_on_macos_is_resized_by_appkit_in_its_width_only() { + let mut dock = NativeDock::on(Os::Mac, Arc::new(FakeSystem::new())); + let mut at = FLOAT_AT; + // The OS follows the window commands of each frame, and the window reports where it is. + let follow = |dock: &mut NativeDock, at: &mut Rect, events: Vec| { + let commands = dock.frame(events).1; + *at = placed_by(&commands, *at); + dock.windows.child_info(info(true, *at)); + commands + }; + dock.workspace.apply(Action::set_iconic(1, true), false, |_| Permissions::ALL).expect("the column collapses"); + for _ in 0..3 { + follow(&mut dock, &mut at, vec![]); + } + let strip = at; + let builder = dock.builder.clone().expect("the palette's window opened"); + assert_eq!(builder.resizable, Some(true), "the collapsed window is resizable"); + let (least, most) = (builder.min_inner_size.expect("a least size"), builder.max_inner_size.expect("a most size")); + assert!(least.y == most.y && (least.y - strip.height()).abs() <= 0.5, "the height is fixed to the strip's: {least:?}..{most:?}, {strip:?}"); + assert!(least.x < most.x, "the width resizes: {least:?}..{most:?}"); + + // A press and drag at the strip's free side, in its title row, clear of the double arrow at the end it keeps to: + // no app grip stands there, so nothing asks the OS for a resize. + let end = strip.max.x >= FLOAT_AT.max.x - 1.0 && strip.min.x > FLOAT_AT.min.x + 1.0; + let side = Pos2::new(if end { 2.0 } else { strip.width() - 2.0 }, 4.0); + let mut sent = Vec::new(); + for events in [vec![moved(side)], vec![press(side)], vec![moved(side + Vec2::new(0.0, 1.0))], vec![release(side)], vec![]] { + sent.extend(follow(&mut dock, &mut at, events)); + } + assert!(!sent.iter().any(|command| matches!(command, ViewportCommand::BeginResize(_))), "the app stands no grip: {sent:?}"); + + // AppKit widens the window. + let width = strip.width() + 60.0; + at = Rect::from_min_size(at.min, Vec2::new(width, at.height())); + dock.windows.child_info(info(true, at)); + let mut sent = Vec::new(); + for _ in 0..3 { + sent.extend(follow(&mut dock, &mut at, vec![])); + } + let palette = &dock.workspace.layout.floating[0]; + assert!(palette.column.iconic_width.is_some_and(|kept| (kept - width).abs() <= 0.5), "the column keeps the width: {:?}", palette.column); + let recorded = palette.native.clone().expect("the model records the window"); + assert_eq!(Vec2::from(recorded.normal.size), FLOAT_AT.size(), "the model keeps the expanded size"); + assert!(!sent.iter().any(|command| matches!(command, ViewportCommand::InnerSize(_))), "no size goes back: {sent:?}"); + assert_eq!(at.width(), width, "the window keeps the width the OS gave it"); +} + /// On a display at 125 % (Windows), a click on the double arrow of a native palette collapsed to icons expands its /// column, and the OS window takes its expanded size. #[trial] diff --git a/docs/ui-docking.md b/docs/ui-docking.md index dfcfa9946..a6ab3fd4f 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -122,7 +122,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 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. The title row is one text row high (`HeaderStrength::Bar`). A window in the main window keeps a band above it for its top grip (`contract::grip_band`), so the grip never covers the row; an OS window keeps none, and on macOS AppKit resizes it from its own edges, with no app grips there (`DockSizes::window_chrome`). A collapsed window shows its icons against the edge of the float area it keeps to, under a title row of the band and the double arrow alone (a context request on the band opens the window's menu), 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 app runs that move (`Overlay::moved_by_app`, which the group's mount carries, so the window is opened knowing it). 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. The title row is one text row high (`HeaderStrength::Bar`). A window in the main window keeps a band above it for its top grip (`contract::grip_band`), so the grip never covers the row; an OS window keeps none, and on macOS AppKit resizes it from its own edges, with no app grips there (`DockSizes::window_chrome`). A collapsed window shows its icons against the edge of the float area it keeps to, under a title row of the band and the double arrow alone (a context request on the band opens the window's menu), and keeps its expanded size for when it expands. Its sides resize its width, and only its width, within the bounds of a docked collapsed column (`DockSizes::iconic_bounds`), on every platform and in the main window alike; names show beside the icons from `IconicSizes::labels`, and the width is the column's `iconic_width` (`Action::ResizeIconic`, `FloatingGroupOutput::collapsed_width`), kept across collapse and expand. 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 app runs that move (`Overlay::moved_by_app`, which the group's mount carries, so the window is opened knowing it). 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.