From e49a32947a15e8b5cecbc2d2cfa238b9259b4a83 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 25 Nov 2026 10:00:18 +0700 Subject: [PATCH] tabs, dock: PanelTabLook::Block shows a panel strip's shown tab as a square surface.control block as tall as the strip, a hovered tab in state.hover; a dock group's strip lies on surface.canvas under it and its panel menu button stands in the strip's middle, as beside pill tabs; Plain stays the default --- crates/ui-panels/src/docking/config.rs | 5 ++-- crates/ui-panels/src/docking/group.rs | 27 ++++++++++++++++----- crates/ui-panels/src/docking/stories.rs | 16 ++++++++++++ crates/ui-panels/tests/it/dock_group.rs | 14 ++++++----- crates/ui-widgets/src/tabs/rules.rs | 4 +++ crates/ui-widgets/src/tabs/strip/stories.rs | 7 ++++++ crates/ui-widgets/src/tabs/tab.rs | 3 +++ 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/crates/ui-panels/src/docking/config.rs b/crates/ui-panels/src/docking/config.rs index be2d0180e6..4f0e2232e9 100644 --- a/crates/ui-panels/src/docking/config.rs +++ b/crates/ui-panels/src/docking/config.rs @@ -99,8 +99,9 @@ pub struct DockConfig { pub titled_headers: bool, /// The wheel over a tab strip shows the next or previous panel, one per wheel notch. pub wheel_selects_tabs: bool, - /// The look of the groups' panel tabs: the shown tab on the panel surface ([`PanelTabLook::Plain`]), or on a - /// filled rounded pill ([`PanelTabLook::Pill`]). + /// The look of the groups' panel tabs: the shown tab on the panel surface ([`PanelTabLook::Plain`]), on a + /// filled rounded pill ([`PanelTabLook::Pill`]), or a square filled block on a canvas strip + /// ([`PanelTabLook::Block`]). pub tab_look: PanelTabLook, /// A floating window opens in an OS window of its own where the window host opens OS windows and reports where /// they are on the desktop (not on Wayland) and its panels allow it (`PanelSpec::allow_native`). Elsewhere, and diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 395ab4a49f..bc4a31f9a7 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -372,8 +372,7 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> { /// The wheel over the tabs shows the next or previous panel, one per wheel notch. #[prop(flag)] wheel_selects_tabs: bool, - /// The look of the tabs ([`DockConfig::tab_look`](super::DockConfig::tab_look)). - #[prop] + /// The look of the tabs: [`tab_look`](DockGroup::tab_look). tab_look: PanelTabLook, /// The header shows the shown panel's title (with its count) and a close button in place of the tab strip, as a /// single titled panel does: the panels are shown from a rail, not by tabs. @@ -422,8 +421,10 @@ impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup< /// The group named by `anchor` (one of its panels) with its `panels`, `active` showing. The group is named by the /// active panel's title. pub fn new(anchor: P, panels: Titles, active: PanelKey) -> Self { - let props = - ContainerProps::new().sizing(Sizing::Fill).header(HeaderRegion::new().fill(SurfaceKind::Background)).command_scope(DockCommands::SCOPE); + let props = ContainerProps::new() + .sizing(Sizing::Fill) + .header(HeaderRegion::new().fill(strip_surface(PanelTabLook::Plain))) + .command_scope(DockCommands::SCOPE); let title = panels.as_slice().iter().find(|panel| panel.key == active).map(|panel| panel.title.clone()).unwrap_or_default(); DockGroup { common: Common::new(), @@ -472,6 +473,15 @@ impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup< DockGroup { take_focus: true, ..self } } + /// The look of the tabs ([`DockConfig::tab_look`](super::DockConfig::tab_look)). [`PanelTabLook::Block`] tabs + /// lie on a strip of `surface.canvas`, the others on the window's background. + #[must_use] + pub fn tab_look(mut self, look: PanelTabLook) -> Self { + self.props = self.props.header(HeaderRegion::new().fill(strip_surface(look))); + self.tab_look = look; + self + } + /// Whether the panel menu button shows: it is asked for and the group has a menu. fn shows_menu_button(&self) -> bool { self.panel_menu_shown && self.menu.is_some() @@ -505,7 +515,7 @@ impl Component for /// The band the group is dragged by and the panel menu button, at the end of the header: the band first. The /// button sits at the strip's top, level with the tab labels' caps, as the "…" of the old tab strips did; beside - /// [`PanelTabLook::Pill`] tabs, in the strip's middle with their pills. + /// [`PanelTabLook::Pill`] and [`PanelTabLook::Block`] tabs, in the strip's middle. fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) { let Some(slot) = cx.header_slot(HeaderEdge::End) else { return }; let words = cx.words::(); @@ -518,7 +528,7 @@ impl Component for let side = (slot.width() - grip_width(cx.tokens) - cx.tokens.space.gap.item).max(0.0); let end = rest.take_end(side).0; let height = side.min(slot.height()); - let top = if self.tab_look == PanelTabLook::Pill { slot.center().y - height / 2.0 } else { slot.top() }; + let top = if self.tab_look == PanelTabLook::Plain { slot.top() } else { slot.center().y - height / 2.0 }; let button = Rect::from_min_size(egui::Pos2::new(end.left(), top), Vec2::new(end.width(), height)); let _ = cx .header_part(HeaderEdge::End, MENU, button) @@ -825,6 +835,11 @@ enum TabEvent { DragStarted, } +/// The surface a dock's strips lie on with tabs in `look`: its groups' tab strips and its columns' bars. +pub(crate) fn strip_surface(look: PanelTabLook) -> SurfaceKind { + if look == PanelTabLook::Block { SurfaceKind::Canvas } else { SurfaceKind::Background } +} + /// The props of a group's tab row: the tabs and how they show, the group's size where a tab's drag starts, and the /// outbox for what the user did. #[derive(MemoProps)] diff --git a/crates/ui-panels/src/docking/stories.rs b/crates/ui-panels/src/docking/stories.rs index e07ee8e397..1515988b56 100644 --- a/crates/ui-panels/src/docking/stories.rs +++ b/crates/ui-panels/src/docking/stories.rs @@ -170,6 +170,22 @@ fn pill_tabs_and_the_panel_menu(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { .into() } +/// VectorCraft 0.24's group header (`DockConfig::tab_look(PanelTabLook::Block)`): the shown tab a square +/// `surface.control` block as tall as the strip, the strip on `surface.canvas`, and the panel menu button in the +/// strip's middle at its end. +#[story(DockGroup<'static, usize>, covers = [Default])] +fn block_tabs_and_the_panel_menu(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + let panels = titles(&[LAYERS, CHANNELS]); + let rows = [DockCommands::FloatPanel, DockCommands::FloatGroup].map(|command| PanelRow::Command(CommandRef::from(command))).to_vec(); + DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key) + .menu(move || rows.clone()) + .panel_menu_icon(IconId::new("menu")) + .tab_look(PanelTabLook::Block) + .show(ui, |_, _| ()) + .output + .into() +} + #[story(GroupGrip, covers = [Default])] fn a_group_grip(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { GroupGrip::new(DragUnit::Group(LAYERS), PanelKey::of(&LAYERS)).label("Move tab group").show(ui).into() diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs index 44240a12a4..b76f4b2753 100644 --- a/crates/ui-panels/tests/it/dock_group.rs +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -65,10 +65,10 @@ fn the_shown_panels_caption_sits_under_the_tabs_and_its_count_names_its_tab() { assert!(fixture.by_label("2 replies").is_none(), "Comments' caption goes with it"); } -// Beside pill tabs (VectorCraft's) the panel menu button stands in the strip's middle, level with the shown tab's pill; -// beside plain tabs it keeps to the strip's top. +// Beside pill and block tabs (VectorCraft's) the panel menu button stands in the strip's middle, level with the shown +// tab's middle; beside plain tabs it keeps to the strip's top. #[trial] -fn the_panel_menu_button_stands_level_with_pill_tabs() { +fn the_panel_menu_button_stands_level_with_pill_and_block_tabs() { use craft_ui::menu::PanelRow; use craft_ui::tabs::PanelTabLook; let middles = |look: PanelTabLook| { @@ -82,10 +82,12 @@ fn the_panel_menu_button_stands_level_with_pill_tabs() { let Some(menu) = fixture.by_label("Panel Menu") else { panic!("the panel menu button shows") }; (tab.rect.center().y, menu.rect) }; - let (tab, menu) = middles(PanelTabLook::Pill); - assert!((menu.center().y - tab).abs() <= 0.5, "the menu button {menu:?} is level with the pill tab's middle {tab}"); let (_, plain) = middles(PanelTabLook::Plain); - assert!(menu.top() > plain.top() + 0.5, "beside plain tabs the button {plain:?} keeps to the strip's top, above {menu:?}"); + for look in [PanelTabLook::Pill, PanelTabLook::Block] { + let (tab, menu) = middles(look); + assert!((menu.center().y - tab).abs() <= 0.5, "beside {look:?} tabs the menu button {menu:?} is level with the tab's middle {tab}"); + assert!(menu.top() > plain.top() + 0.5, "beside plain tabs the button {plain:?} keeps to the strip's top, above {menu:?}"); + } } // A titled group shows the shown panel's name as a heading with its count and a close button, not a tab strip: the diff --git a/crates/ui-widgets/src/tabs/rules.rs b/crates/ui-widgets/src/tabs/rules.rs index 4761a6b60a..5f7b55dd2a 100644 --- a/crates/ui-widgets/src/tabs/rules.rs +++ b/crates/ui-widgets/src/tabs/rules.rs @@ -31,6 +31,10 @@ pub enum PanelTabLook { /// small control high in the middle of the strip; a tab under the pointer shows the pill too. A dock group's panel /// menu button stands in the strip's middle with them. Pill, + /// VectorCraft 0.24's tabs: the shown tab a square `surface.control` block as tall as the strip, a tab under the + /// pointer `state.hover`. A dock group's strip lies on `surface.canvas`, and its panel menu button stands in the + /// strip's middle. + Block, } /// The kind of a strip. It sets the defaults below; the host picks one per strip. diff --git a/crates/ui-widgets/src/tabs/strip/stories.rs b/crates/ui-widgets/src/tabs/strip/stories.rs index ca8a83e381..a906955ebd 100644 --- a/crates/ui-widgets/src/tabs/strip/stories.rs +++ b/crates/ui-widgets/src/tabs/strip/stories.rs @@ -101,6 +101,13 @@ fn tab_strip_panel_pill(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { strip(ui, data, TabStrip::new("Panels").shown(1).panel_look(PanelTabLook::Pill), &TITLES, 4, TabKind::Panel) } +/// Panel tabs in the block look (`PanelTabLook::Block`, a dock's `DockConfig::tab_look`): the shown tab a square +/// `surface.control` block as tall as the strip, the others bare until the pointer rests on one. +#[story(TabStrip<'static, usize>, covers = [], drive = Drive::Never)] +fn tab_strip_panel_block(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + strip(ui, data, TabStrip::new("Panels").shown(1).panel_look(PanelTabLook::Block), &TITLES, 4, TabKind::Panel) +} + /// The width the narrow panel story's room is held to: the shown tab whole, the others at their first letters. const NARROW_ROOM: f32 = 260.0; diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 9fd51638b3..c030b56e80 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -421,6 +421,9 @@ impl Component for Tab<'_> { Stateful::new(c(clear)).off(States::new(c(clear), hover, c(clear), c(clear))).on(States::new(c(clear), c(clear), c(clear), c(clear))) } else if text_only { Stateful::new(c(clear)) + } else if key.kind == TabKind::Panel && key.panel_look == PanelTabLook::Block { + let control = c(colors.surface.control); + Stateful::new(c(clear)).off(States::new(c(clear), hover, hover, c(clear))).on(States::new(control, control, control, control)) } else { Stateful::new(c(clear)).off(States::new(c(clear), c(panel), c(panel), c(clear))).on(States::new(c(panel), c(panel), c(panel), c(panel))) };