diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index e0eb261422..c2056cd615 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -6,7 +6,9 @@ use super::dock_column::{ register_edges, show_bar, }; use super::group::GripMarks; -use super::{CardInset, DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, GroupAt, PanelKey, PanelSpec, Splitter, start_icon_drag}; +use super::{ + CardInset, DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, FlyoutHeight, GroupAt, PanelKey, PanelSpec, Splitter, start_icon_drag, +}; use crate::buttons::IconButton; use crate::contract::overlay::{Anchor, PopupLayer}; use crate::contract::{ @@ -181,10 +183,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`). /// The flyouts stand above the floating windows as popups do, or below them with `flyout_layer` set to /// `PopupLayer::BelowWindows`, which a dock area sets for its docked columns from `DockConfig::flyout_layer`. /// @@ -425,12 +429,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 99eb56e325..b94a90d667 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 56225e0aa6..3478c3a6d1 100644
--- a/crates/ui-panels/src/docking/mod.rs
+++ b/crates/ui-panels/src/docking/mod.rs
@@ -45,7 +45,7 @@ pub use panels::{close_requests, open_requests};
pub use placed::{Placing, placed_rect, with_area_rules};
pub use root::{DockRoot, DockRootOutput, DockRootStyle};
pub use sources::{DividerKind, DockSource, SourceKind};
-pub use spec::{DockGrid, DockHeights, PanelSpec};
+pub use spec::{DockGrid, DockHeights, FlyoutHeight, PanelSpec};
pub use splitter::{Splitter, SplitterStyle};
pub use targets::{CardInset, 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 2aef553213..6780de49cb 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