From 0be3d77cdfa819ff6b3a240ed43a6d2a9ee93eb6 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Tue, 24 Nov 2026 16:47:26 +0100 Subject: [PATCH] ui-panels docking: a panel's flyout can be as tall as its body (PanelSpec::flyout_height) An iconic column's flyout took at least the DockHeights default of each of its group's panels, so a panel given a tall docked height also opened a tall flyout over a short body. FlyoutHeight::Docked, the default, keeps that; FlyoutHeight::Content opens the flyout as tall as its body measures, while the panel's DockHeights still size its group docked in a column. Trial a_content_tall_flyout_ignores_the_docked_height_that_its_docked_group_keeps. --- crates/ui-panels/src/docking/iconic.rs | 19 +++-- crates/ui-panels/src/docking/iconic/trials.rs | 78 ++++++++++++++++++- crates/ui-panels/src/docking/mod.rs | 2 +- crates/ui-panels/src/docking/spec.rs | 28 ++++++- docs/ui-docking.md | 3 +- 5 files changed, 117 insertions(+), 13 deletions(-) diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index 42e0c7f4d2..a476b960aa 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -6,7 +6,7 @@ use super::dock_column::{ register_edges, show_bar, }; use super::group::GripMarks; -use super::{DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, GroupAt, PanelKey, PanelSpec, Splitter, start_icon_drag}; +use super::{DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, FlyoutHeight, GroupAt, PanelKey, PanelSpec, Splitter, start_icon_drag}; use crate::buttons::IconButton; use crate::contract::overlay::Anchor; use crate::contract::{ @@ -181,10 +181,12 @@ pub struct IconicColumnStyle { /// column registers its drop spots with the dock `dock` as an expanded column does: its edges, the seams between its /// icon groups, the top and bottom of the stack and each icon group's cells, which join its tabs. The flyout shows /// its group through the `view` of [`show_flyouts`](IconicColumn::show_flyouts), with the opened panel active, as tall as the view measures the -/// group within the room and at least the height of its panels' default heights; a group the user sized keeps that -/// size. The flyout's top is level with its group's icons, shifted by the group's `flyout_offset`, inside `within`. -/// 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`). +/// group within the room and at least the default height ([`DockHeights`](super::DockHeights)) of each of its panels +/// whose [`FlyoutHeight`] is `Docked`, the default: a panel whose flyout is `Content` tall leaves its docked heights to +/// its group docked in a column. A group the user sized keeps that size. The flyout's top is level with its group's +/// icons, shifted by the group's `flyout_offset`, inside `within`. 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 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. @@ -418,12 +420,15 @@ impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> { Plan { bar, cells, names, grips, groups, body } } - /// The height of the flyout of `group`: the group's own height, else what its panels ask for, else the least. + /// The height of the flyout of `group`: the group's own height, else the docked default heights of its panels + /// whose flyout takes them ([`FlyoutHeight::Docked`]), else the least. fn flyout_height(&self, group: &Group

, sizes: &DockSizes) -> f32 { let content = group .panels .iter() - .filter_map(|panel| (self.spec)(panel).heights.filter(|heights| heights.valid())) + .map(|panel| (self.spec)(panel)) + .filter(|spec| spec.flyout_height == FlyoutHeight::Docked) + .filter_map(|spec| spec.heights.filter(|heights| heights.valid())) .map(|heights| heights.default + sizes.strip) .fold(sizes.strip + sizes.least, f32::max); group.height.filter(|height| height.is_finite() && *height > 0.0).unwrap_or(content).max(sizes.strip + sizes.least) diff --git a/crates/ui-panels/src/docking/iconic/trials.rs b/crates/ui-panels/src/docking/iconic/trials.rs index 1b1f02a339..18cec2e784 100644 --- a/crates/ui-panels/src/docking/iconic/trials.rs +++ b/crates/ui-panels/src/docking/iconic/trials.rs @@ -1,5 +1,5 @@ //! Trials of `IconicColumn`: the letter of a panel without an icon, the names a wide column shows, the grips of its -//! groups, the resizes of its flyouts, and a flyout that a command leaves open. +//! groups, the heights and resizes of its flyouts, and a flyout that a command leaves open. #![allow(clippy::panic, clippy::expect_used, reason = "trials assert by panicking")] use super::GRIP; @@ -8,7 +8,8 @@ use crate::contract::overlay::{self, OpenFilter}; use crate::contract::{Bind, Show as _, ShowContainer as _}; use crate::docking::group::GRIP_ABOVE; use crate::docking::{ - DockHeights, DockSizes, DockSpot, DockTargets, DragUnit, FlyoutResize, GroupAt, GroupDrag, GroupGrip, IconicColumn, PanelKey, PanelSpec, + DockColumn, DockHeights, DockSizes, DockSpot, DockTargets, DragUnit, FlyoutHeight, FlyoutResize, GroupAt, GroupDrag, GroupGrip, IconicColumn, + PanelKey, PanelSpec, }; use crate::runtime::commands::{AppCatalog, Binding, CommandDef, CommandInput, Scope}; use crate::runtime::drag; @@ -420,6 +421,79 @@ fn a_flyout_with_an_offset_in_a_short_viewport_stays_inside_and_resizes_its_widt } } +/// The body height a panel asks for docked in a column, well above what its one-line body measures. +const DOCKED: f32 = 260.0; + +/// A panel with a one-line body that asks for [`DOCKED`] in a dock column, its flyout `height` tall; the other panel +/// asks for no height. +fn docked_tall(height: FlyoutHeight) -> impl Fn(&u8) -> PanelSpec { + move |panel| match panel { + 0 => PanelSpec::new("Swatches").heights(DockHeights::new(DOCKED)).flyout_height(height), + _ => PanelSpec::new("Brushes"), + } +} + +/// What a group with a one-line body measures in the trials: its strip, the body's padding and a line, four strips. +fn one_line(sizes: &DockSizes) -> f32 { + sizes.strip * 4.0 +} + +/// The height of the flyout of the [`docked_tall`] panel at `height`, whose group measures [`one_line`], and the dock +/// sizes it showed in. +fn flyout_height_of(height: FlyoutHeight) -> (f32, DockSizes) { + let shown = Rc::new(Cell::new(None)); + let (seen, open) = (Rc::clone(&shown), Cell::new(None)); + let spec = docked_tall(height); + let place = Rect::from_min_size(Pos2::ZERO, Vec2::new(RAIL, SCREEN.y)); + let mut fixture = Fixture::new(move |ui| { + let column = Column::new(vec![Group::new(vec![0], 0)]); + let measured = one_line(&StyleCx::with_root(ui.ctx(), DockSizes::style)); + let mut now = open.get(); + IconicColumn::new("Panels", global("iconic column", "flyout height"), &column, Bind::bound(&mut now), &spec) + .within(screen()) + .show_flyouts_at(ui, place, |_, at, _, _| match at { + GroupAt::Measure(_) => Some(measured), + GroupAt::Show(rect) => { + seen.set(Some(rect)); + None + } + }); + open.set(now); + }); + fixture.room(SCREEN).settle(); + let icon = fixture.by_label("Swatches").expect("the Swatches icon").rect.center(); + fixture.click_at(icon).settle(); + (shown.get().expect("the flyout is open").height(), StyleCx::with_root(fixture.ctx(), DockSizes::style)) +} + +/// A panel that asks for a tall docked height opens a flyout at least that tall by default; with +/// `FlyoutHeight::Content` its flyout is as tall as its one-line body measures, while docked in a column its group +/// keeps the docked height. +#[trial] +fn a_content_tall_flyout_ignores_the_docked_height_that_its_docked_group_keeps() { + let (by_default, sizes) = flyout_height_of(FlyoutHeight::Docked); + let (docked, measured) = (DOCKED + sizes.strip, one_line(&sizes)); + assert!(measured < docked && measured > sizes.strip + sizes.least, "the body measures between the least and the docked height"); + assert!(near(by_default, docked), "by default the flyout takes the docked height: {by_default} for {docked}"); + let (content, _) = flyout_height_of(FlyoutHeight::Content); + assert!(near(content, measured), "a content-tall flyout is as tall as its body measures: {content} for {measured}"); + + let rects = Rc::new(RefCell::new(Vec::new())); + let seen = Rc::clone(&rects); + let spec = docked_tall(FlyoutHeight::Content); + let mut fixture = Fixture::new(move |ui| { + let column = Column::new(vec![Group::new(vec![0], 0), Group::new(vec![1], 0)]); + let mut shown = Vec::new(); + DockColumn::new("Panels", global("dock column", "flyout height"), &column, &spec).show_groups(ui, |group, rect, _, _| { + shown.push((group.panels.first().copied(), rect)); + }); + *seen.borrow_mut() = shown; + }); + fixture.room(SCREEN).settle(); + let group = rects.borrow().iter().find(|(panel, _)| *panel == Some(0)).map(|(_, rect)| *rect).expect("the docked group shows"); + assert!(near(group.height(), docked), "docked in a column the group keeps its docked height: {group:?} for {docked}"); +} + /// Each icon group's grip strip has its own room at the group's top: across the group, below the bar or the group /// before it and above the group's first icon, overlapping no icon. A drag that starts on a grip moves its whole /// group, as a drag on an icon moves its panel. diff --git a/crates/ui-panels/src/docking/mod.rs b/crates/ui-panels/src/docking/mod.rs index 37ceceb30e..5689a56718 100644 --- a/crates/ui-panels/src/docking/mod.rs +++ b/crates/ui-panels/src/docking/mod.rs @@ -43,7 +43,7 @@ pub use panels::{DockPanels, PanelSpecs, SpecSource, request_actions}; pub use panels::{close_requests, open_requests}; pub use placed::{Placing, placed_rect, with_area_rules}; pub use root::{DockRoot, DockRootOutput, DockRootStyle}; -pub use spec::{DockGrid, DockHeights, PanelSpec}; +pub use spec::{DockGrid, DockHeights, FlyoutHeight, PanelSpec}; pub use splitter::{Splitter, SplitterStyle}; pub use targets::{DockSizes, DockSpot, DockTargets, GroupDrag, ZoneRule}; pub use words::DockWords; diff --git a/crates/ui-panels/src/docking/spec.rs b/crates/ui-panels/src/docking/spec.rs index 2fed17f8f8..d90b7a58fb 100644 --- a/crates/ui-panels/src/docking/spec.rs +++ b/crates/ui-panels/src/docking/spec.rs @@ -51,6 +51,19 @@ impl DockHeights { } } +/// How tall the flyout of a panel in a column collapsed to icons opens while the user has not resized its group. Either +/// way the flyout is at least as tall as its body measures, within the room below its top. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum FlyoutHeight { + /// At least the panel's [`DockHeights::default`], the height its group takes docked in a column. + #[default] + Docked, + /// As tall as the body measures, at least the dock's least group height: the panel's [`DockHeights`] size its + /// group docked in a column only. + Content, +} + /// How a panel that lays its content in a grid of equal columns (a toolbar) sizes its dock column. The column is a /// whole number of content columns wide, its steps ([`Column::steps`](craft_behavior::dock::Column::steps)), and as /// tall as the content measures at that width: docked from the top of the dock, floating under the title row. A drag @@ -162,9 +175,12 @@ pub struct PanelSpec { pub icon: Option>, /// Body size limits. pub limits: SizeLimits, - /// How the panel's group sizes itself in a dock column until the user resizes it. `None` shares the column's - /// free height with the column's last open group, which fills it, and with the other groups that have none. + /// How the panel's group sizes itself in a dock column until the user resizes it, and under + /// [`FlyoutHeight::Docked`] the least height of its flyout. `None` shares the column's free height with the + /// column's last open group, which fills it, and with the other groups that have none. pub heights: Option, + /// How tall the panel's flyout opens: at least its docked default height, or as tall as its body measures. + pub flyout_height: FlyoutHeight, /// The size the panel floats at: its width and the most height it takes. `None`: the size of the group it floats /// out of, else `FloatSpace`'s default size. pub float_size: Option, @@ -201,6 +217,7 @@ impl PanelSpec { icon: None, limits: SizeLimits::default(), heights: None, + flyout_height: FlyoutHeight::Docked, float_size: None, allow_native: true, window_kind: WindowKind::Tool, @@ -262,6 +279,13 @@ impl PanelSpec { self } + /// How tall the panel's flyout opens. + #[must_use] + pub fn flyout_height(mut self, height: FlyoutHeight) -> Self { + self.flyout_height = height; + self + } + /// The size the panel floats at. #[must_use] pub fn float_size(mut self, size: Vec2) -> Self { diff --git a/docs/ui-docking.md b/docs/ui-docking.md index 081948655d..1afbd4a8f2 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -56,7 +56,7 @@ The host keeps its panels' specs in a plain-data model that implements `PanelSpe | Method | Does | | --- | --- | -| `spec` | The panel's `PanelSpec`: label, icon, `SizeLimits`, `DockHeights`, float size, `allow_native`, `window_kind`, `canvas`, `grid`. | +| `spec` | The panel's `PanelSpec`: label, icon, `SizeLimits`, `DockHeights`, `FlyoutHeight`, float size, `allow_native`, `window_kind`, `canvas`, `grid`. | | `permissions` | The panel's `Permissions` (default `ALL`). | The area reads them only when the model's revision, the workspace's revision or the lock changes (`runtime::derived`), and keeps what it read otherwise, so an idle pass reads no spec. A host changes a label or a limit by editing the model. A spec reads no style: a tool rail's grid is `DockGrid::rail(cells)`, which the dock sizes from its own tokens. @@ -120,6 +120,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords - A drag ends without a change when another arrangement replaces the workspace it started on: it records the workspace's generation, which `Workspace::replace` and the `WorkspaceSet` switch and reset change. The dock's own edits keep the generation, so they keep the drag. Every write moves the workspace's revision (`Workspace::revision`), which keys what the area derives. - A floating window's id comes from a counter its layout owns (`Layout::fresh_window_id`). It starts above every id the layout is built or loaded with and only grows while the layout lives; `Workspace::replace` gives the incoming windows ids the replaced layout never gave out, and a dock area keeps the windows its actions add above every id it has shown, so a workspace an undo brings back draws no id twice (`Workspace::raise_window_floor`). An OS window never passes to another window. - A dock column's last open group fills the column: it takes the height the other groups leave and asks for its `DockHeights::fill`. The other groups keep the height the user gave them, or take their `DockHeights::default`, which shrinks towards `compact` before the filling group gets less than its fill. Groups that ask for no heights share the free height with the filling group. +- A flyout is as tall as its group measures, within the room below its top, and at least the `DockHeights::default` of each of its panels whose `PanelSpec::flyout_height` is `FlyoutHeight::Docked`, the default. A panel with `FlyoutHeight::Content` opens a flyout as tall as its body measures, while its `DockHeights` still size its group docked in a column. A group the user sized keeps that height. - Split handles are Tab stops, and the arrow keys move them. A divider drag is one gesture in `DockAreaOutput::edit`. - A panel command (`DockCommands`) acts on the shown panel of the group that takes it. A menu row, a key and the command palette run the same code: `actions` turns the command into `Action`s.