diff --git a/crates/ui-panels/src/docking/flyout.rs b/crates/ui-panels/src/docking/flyout.rs index a17f91b56..8b62c56a1 100644 --- a/crates/ui-panels/src/docking/flyout.rs +++ b/crates/ui-panels/src/docking/flyout.rs @@ -1,6 +1,6 @@ //! `Flyout`: the panel an icon of an iconic column opens beside the column. -use crate::contract::overlay::{Anchor, Dismiss, FloatPlace, Place, PlacementChange, ResizeEdges}; +use crate::contract::overlay::{Anchor, Dismiss, FloatPlace, Outside, Place, PlacementChange, ResizeEdges}; use crate::contract::{ BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, OverlayUi, Pad, PopupHandle, Role, SizeLimits, Sizing, }; @@ -48,8 +48,8 @@ impl Outcome for FlyoutOutput { } } -/// A popup beside an iconic column, on the side of the canvas, whose top left the caller places. Escape and a press -/// outside close it; with Auto-Collapse Iconic Panels the focus leaving it closes it too. Its body is measured at the +/// A popup beside an iconic column, on the side of the canvas, whose top left the caller places. Escape closes it; with +/// Auto-Collapse Iconic Panels a press outside it and the focus leaving it close it too. Its body is measured at the /// flyout's width first: the flyout is as tall as the body measures within the room below its top, and at least its /// `size`'s height, and the body then shows in the rect that takes. /// @@ -77,7 +77,7 @@ pub struct Flyout { impl Flyout { /// A flyout at least `size` that opens on the side `opens` of its column, in reading order (`Side::Start` or - /// `Side::End`), closing when the focus leaves it if `auto_collapse`. + /// `Side::End`), closing on a press outside it and when the focus leaves it if `auto_collapse`. pub fn new(opens: Side, size: Vec2, auto_collapse: bool) -> Self { let props = ContainerProps::new().surface(SurfaceKind::Popup).pad(Pad::None).sizing(Sizing::Content); Flyout { common: Common::new(), props, opens, size, auto_collapse, within: Rect::EVERYTHING, least: Vec2::ZERO, placed: None } @@ -96,7 +96,7 @@ impl Flyout { .placed_at(top_left) .size_limits(SizeLimits::at_least(least)) .resize_edges(free.union(ResizeEdges::TOP).union(ResizeEdges::BOTTOM)) - .dismiss(Dismiss::new().focus_left(self.auto_collapse)) + .dismiss(Dismiss::new().outside(if self.auto_collapse { Outside::Close } else { Outside::Keep }).focus_left(self.auto_collapse)) .body_scroll(false); if bounded { overlay.bounds(self.within) } else { overlay } } diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index 9a602d4e5..d4304070f 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -153,9 +153,8 @@ pub struct IconicColumnStyle { /// icon, cut with an ellipsis to the cell; a click or drag on the name acts as one on the icon. A click or Enter on an icon /// opens the flyout of its panel beside the column, switches it to that panel or closes it; one flyout is open at a /// time. A drag of an icon starts a move of its panel, a drag of the grip on top of a group a move of the group, a -/// drag of the bar beside its button a move of the column; each starts through the drag session, and a press outside -/// the flyout closes it. Escape and a press -/// outside close the flyout; with `auto_collapse` the focus leaving it does too. +/// drag of the bar beside its button a move of the column; each starts through the drag session. Escape closes the +/// flyout; with `auto_collapse` a press outside it and the focus leaving it do too. /// /// The open flyout is the bound `Option
` of [`new`](IconicColumn::new), owned by the host like the layout: a click /// on an icon, Escape and auto-collapse write it, and the host opens a panel (the Window menu) by writing it. The diff --git a/crates/ui-panels/src/docking/iconic/trials.rs b/crates/ui-panels/src/docking/iconic/trials.rs index 12bbcfb5e..65ad0bdbf 100644 --- a/crates/ui-panels/src/docking/iconic/trials.rs +++ b/crates/ui-panels/src/docking/iconic/trials.rs @@ -140,6 +140,11 @@ struct Flyouts { impl Flyouts { /// A column of `groups` on the right window edge when `right`, else the left one; its flyouts stay in `within`. fn new(groups: &[&[u8]], right: bool, within: Rect) -> Self { + Self::with(groups, right, within, false) + } + + /// [`Flyouts::new`] with Auto-Collapse Iconic Panels on when `auto_collapse`. + fn with(groups: &[&[u8]], right: bool, within: Rect, auto_collapse: bool) -> Self { let mut column = Column::new(groups.iter().map(|panels| Group::new(panels.to_vec(), 0)).collect()); column.iconic = true; let edge = if right { DockEdge::End } else { DockEdge::Start }; @@ -159,6 +164,7 @@ impl Flyouts { .edge(edge) .opens(if right { Side::Start } else { Side::End }) .within(within) + .auto_collapse(auto_collapse) .show_flyouts_at(ui, place, |group, at, ui, _| { let GroupAt::Show(rect) = at else { return None }; let panel = *group.active_panel()?; @@ -220,6 +226,18 @@ impl Flyouts { } } +/// A press outside the open flyout leaves it open; with Auto-Collapse Iconic Panels on it closes it. +#[trial] +fn a_press_outside_closes_the_flyout_only_with_auto_collapse() { + for auto_collapse in [false, true] { + let mut d = Flyouts::with(&[&[1, 2]], false, screen(), auto_collapse); + d.open("Brushes"); + let away = d.rect().right_center() + Vec2::new(100.0, 0.0); + d.fixture.click_at(away).settle(); + assert_eq!(d.shown.get().is_none(), auto_collapse, "auto-collapse {auto_collapse}: a press outside closes the flyout only with it on"); + } +} + /// The top edge and the free top corner grow the flyout upward on either window edge: the bottom and the column-side /// edge stay, the column-side edge has no grip, and the new top is kept as an offset from the icons, so it survives /// another group's flyout and reopening. diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 6db392557..5e19b696a 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -130,7 +130,7 @@ pub struct DockArea<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> { /// The panel whose frame shows alone. #[prop] maximized: Option
,
- /// Auto-Collapse Iconic Panels: a flyout closes when the focus leaves it.
+ /// Auto-Collapse Iconic Panels: a flyout closes on a press outside it and when the focus leaves it.
#[prop(flag)]
auto_collapse: bool,
/// The workspace is locked: nothing moves, floats or closes.
diff --git a/crates/ui-patterns/tests/it/docking/native.rs b/crates/ui-patterns/tests/it/docking/native.rs
index 999412537..8e774f0f3 100644
--- a/crates/ui-patterns/tests/it/docking/native.rs
+++ b/crates/ui-patterns/tests/it/docking/native.rs
@@ -266,6 +266,8 @@ struct NativeDock {
palette: Option