From fe138f934f96ae8f16b3fe68a03ef0aec6f9fbb1 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 24 Nov 2026 12:35:00 +0700 Subject: [PATCH] docking: DockConfig::panel_menu_always gives every group its panel menu button --- crates/ui-panels/src/docking/config.rs | 11 ++++++ crates/ui-patterns/src/patterns/dock/area.rs | 2 +- .../tests/it/docking/panel_menu.rs | 34 ++++++++++++++++++- docs/ui-docking.md | 1 + 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/crates/ui-panels/src/docking/config.rs b/crates/ui-panels/src/docking/config.rs index 26ecfb20d..d0d49752e 100644 --- a/crates/ui-panels/src/docking/config.rs +++ b/crates/ui-panels/src/docking/config.rs @@ -96,6 +96,9 @@ pub struct DockConfig { pub native_windows: bool, /// Docked groups' menus get Minimize and Move Group Up and Down. pub group_order_items: bool, + /// Every group shows its panel menu button, whose menu holds the dock's own rows when the shown panel has none of + /// its own (`DockPanels::panel_rows`). Off: only a group whose shown panel has rows of its own shows the button. + pub panel_menu_always: bool, /// What the icons of a docked column collapsed to icons open: flyouts, or with [`IconicMode::Rail`] the column /// itself, whose icons then stay beside it while it is expanded. Floating windows' icons open flyouts. pub iconic_mode: IconicMode, @@ -120,6 +123,7 @@ impl Default for DockConfig { wheel_selects_tabs: false, native_windows: true, group_order_items: false, + panel_menu_always: false, iconic_mode: IconicMode::Flyouts, } } @@ -140,6 +144,13 @@ impl DockConfig { self } + /// The panel menu button on every group on or off ([`panel_menu_always`](Self::panel_menu_always)). + #[must_use] + pub fn panel_menu_always(mut self, on: bool) -> Self { + self.panel_menu_always = on; + self + } + /// The picture-frame profile on or off. #[must_use] pub fn side_edge_zones(mut self, on: bool) -> Self { diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 2ebfa1692..3d461f036 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -1093,7 +1093,7 @@ impl Pass<'_, P> { .zones(scene.config.zone_rule()) .movable(scene.permissions(shown).movable) .menu(move || panel_menu_rows(scene, &mut **panels.borrow_mut(), words, shown).0) - .panel_menu_shown(*hosted) + .panel_menu_shown(*hosted || scene.config.panel_menu_always) .command_states(states.clone()); if look.in_window { group = group.in_window(); diff --git a/crates/ui-patterns/tests/it/docking/panel_menu.rs b/crates/ui-patterns/tests/it/docking/panel_menu.rs index b3b76895e..e2bd8fa7a 100644 --- a/crates/ui-patterns/tests/it/docking/panel_menu.rs +++ b/crates/ui-patterns/tests/it/docking/panel_menu.rs @@ -8,7 +8,7 @@ use craft_ui::contract::{Bind, BodyCx, PlainData, Role, ShowContainer as _, Trac use craft_ui::docking::{DockConfig, DockPanels, PanelSpec, PanelSpecs, WindowMenuRows}; use craft_ui::menu::{Menu, PanelRow}; use craft_ui::patterns::dock::DockArea; -use craft_ui::testing::{Fixture, trial}; +use craft_ui::testing::{Fixture, Target, trial}; use egui::{Key, Modifiers, Ui, Vec2}; use std::cell::RefCell; use std::rc::Rc; @@ -35,6 +35,38 @@ impl DockPanels for Panels { } } +/// A host with no rows of its own. +struct Bare; + +impl DockPanels for Bare { + fn body(&mut self, _: &usize, _: &mut Ui, _: &mut BodyCx<'_>) {} +} + +/// The panel menu buttons a dock of two groups shows with `config`, for a host that gives no rows. +fn menu_buttons(config: DockConfig) -> (Fixture, Vec) { + let root = Node::split(Axis::X, SplitSize::Ratio(0.5), Node::tabs(vec![0, 1], 0), Node::tabs(vec![2, 3], 0)); + let mut workspace = Arc::new(Workspace::new(Layout::new(Some(root), Vec::new()))); + let specs = Tracked::new(Specs); + let mut fixture = Fixture::new(move |ui| { + DockArea::new("Dock", Bind::bound(&mut workspace), &specs, &mut Bare, config.clone()).show(ui); + }); + fixture.room(Vec2::new(1200.0, 600.0)).settle(); + let buttons = fixture.by_role(Role::BUTTON).into_iter().filter(|button| fixture.tree().name_of(button.node) == Some("Panel Menu")).collect(); + (fixture, buttons) +} + +/// A panel with no rows of its own shows no menu button, unless the dock shows the button on every group; that +/// button's menu holds the dock's own rows. +#[trial] +fn a_dock_that_shows_the_panel_menu_always_gives_every_group_the_button() { + let (_, hidden) = menu_buttons(DockConfig::default()); + assert!(hidden.is_empty(), "no button for panels without rows"); + let (mut fixture, shown) = menu_buttons(DockConfig::default().panel_menu_always(true)); + assert_eq!(shown.len(), 2, "each group shows its panel menu button"); + fixture.click(&shown[0]).idle(2); + assert!(fixture.by_label("Float").is_some(), "the menu holds the dock's own rows"); +} + /// With the first group's tabs focused, Float in the second group's panel menu floats the second group's panel. #[trial] fn a_panel_menu_command_reaches_the_group_whose_button_opened_it() { diff --git a/docs/ui-docking.md b/docs/ui-docking.md index 8c4937fdf..2ea72bcf2 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -102,6 +102,7 @@ The host handles these `DockEvent`s: | `title_bar_docks` | on | Dragging a floating window's title bar onto a target docks the whole window. | | `close_menu_items`, `close_button` | on | Built-in Close items, and the close action on floating windows. | | `tab_close_buttons` | off | Close buttons on tabs (middle click closes too), for tabs that act as documents. | +| `panel_menu_always` | off | Every group shows its panel menu button, with the dock's own rows when the shown panel has none. Off: only a panel with rows of its own (`DockPanels::panel_rows`) gets the button. | | `native_windows` | on | Floating windows open as OS windows where the window host opens them and reports their positions (not on Wayland) and `PanelSpec::allow_native` allows. | The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords` holds the words.