From 34d7846cd37d86ca6caa7a6465e788ed44d3470c Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 17:11:24 +0700 Subject: [PATCH] ui-panels: a docking flyout closes on a press outside it only with Auto-Collapse Iconic Panels on --- crates/ui-panels/src/docking/flyout.rs | 10 ++--- crates/ui-panels/src/docking/iconic.rs | 5 +-- crates/ui-panels/src/docking/iconic/trials.rs | 18 ++++++++ crates/ui-patterns/src/patterns/dock/area.rs | 2 +- crates/ui-patterns/tests/it/docking/native.rs | 42 +++++++++++-------- 5 files changed, 50 insertions(+), 27 deletions(-) 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, /// The tree the palette window's pass produced in the last frame. palette_tree: Option, + /// Whether Auto-Collapse Iconic Panels is on in the frames of a collapsed palette. + auto_collapse: bool, } impl NativeDock { @@ -287,7 +289,7 @@ impl NativeDock { windows.child_info(info(true, FLOAT_AT)); let workspace = Arc::new(Workspace::new(Layout::new(Some(Node::tabs(vec![2], 0)), vec![palette]))); let specs = Tracked::new(Specs { rights: Permissions::ALL, least: false, stepped }); - let mut dock = NativeDock { windows, workspace, stepped, specs, builder: None, palette: None, palette_tree: None }; + let mut dock = NativeDock { windows, workspace, stepped, specs, builder: None, palette: None, palette_tree: None, auto_collapse: false }; for _ in 0..3 { dock.frame(vec![]); } @@ -1034,10 +1036,10 @@ fn collapsed_palette() -> (NativeDock, Rect) { /// One frame of `dock` with `panels`, `root` events for the main window and `child` events for the palette's window, /// whose OS window follows its commands at `at`: the frame's output. fn collapsed_frame(dock: &mut NativeDock, panels: &mut dyn DockPanels, at: &mut Rect, root: Vec, child: Vec) -> Out { - let workspace = &mut dock.workspace; - let specs = &dock.specs; + let (workspace, specs, auto_collapse) = (&mut dock.workspace, &dock.specs, dock.auto_collapse); let out = dock.windows.frame(root, child, |ui| { - let _ = DockArea::new("Native dock", Bind::bound(workspace), specs, &mut *panels, DockConfig::default()).show(ui); + let area = DockArea::new("Native dock", Bind::bound(workspace), specs, &mut *panels, DockConfig::default()); + let _ = if auto_collapse { area.auto_collapse() } else { area }.show(ui); }); let palette = dock.palette; let commands: Vec = @@ -1222,22 +1224,26 @@ fn a_tooltip_from_a_native_palette_opens_in_a_popup_os_window() { assert!(rect.width() > at.width() && rect.height() < rect.width(), "the tooltip's text runs on one line, wider than the strip: {rect:?}"); } -/// A press in the main window closes the flyout a collapsed native palette opened in a popup window. +/// With Auto-Collapse Iconic Panels on, a press in the main window closes the flyout a collapsed native palette opened +/// in a popup window; with it off the flyout stays open. #[trial] -fn a_press_in_the_main_window_closes_a_native_palettes_flyout() { - let (mut dock, mut at) = collapsed_palette(); - let mut probe = BodyProbe::default(); - let popup = open_flyout(&mut dock, &mut probe, &mut at); - let over = OVER_GROUP - MAIN_AT.min.to_vec2(); - for root in [vec![moved(over)], vec![press(over)], vec![release(over)]] { - collapsed_frame(&mut dock, &mut probe, &mut at, root, vec![]); +fn a_press_in_the_main_window_closes_a_native_palettes_flyout_with_auto_collapse() { + for auto_collapse in [true, false] { + let (mut dock, mut at) = collapsed_palette(); + dock.auto_collapse = auto_collapse; + let mut probe = BodyProbe::default(); + let popup = open_flyout(&mut dock, &mut probe, &mut at); + let over = OVER_GROUP - MAIN_AT.min.to_vec2(); + for root in [vec![moved(over)], vec![press(over)], vec![release(over)]] { + collapsed_frame(&mut dock, &mut probe, &mut at, root, vec![]); + } + // The flyout fades out, then its window closes. + let closed = (0..60).any(|_| { + let out = collapsed_frame(&mut dock, &mut probe, &mut at, vec![], vec![]); + !popups(&dock, &out).contains(&popup) + }); + assert_eq!(closed, auto_collapse, "auto-collapse {auto_collapse}: the flyout's window closed only with it on"); } - // The flyout fades out, then its window closes. - let closed = (0..60).any(|_| { - let out = collapsed_frame(&mut dock, &mut probe, &mut at, vec![], vec![]); - !popups(&dock, &out).contains(&popup) - }); - assert!(closed, "the flyout's window closed"); } /// Palettes no smaller than `PALETTE_LEAST`.