diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 82d7a75e2..ad0dd7e63 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -301,6 +301,8 @@ pub struct DockGroupOutput { pub tabs: Vec<(PanelKey, Rect, Id)>, /// The band the group is dragged by this pass, with the id of its accessibility node. pub grip: Option<(Rect, Id)>, + /// The strip's overflow button, when some tabs do not fit, with the id of its accessibility node. + pub overflow: Option<(Rect, Id)>, } impl Outcome for DockGroupOutput { @@ -336,6 +338,7 @@ struct Reported { /// A drag started on the strip's empty room, which `finish` starts as a drag of the group. empty_drag: bool, tabs: Vec<(PanelKey, Rect, Id)>, + overflow: Option<(Rect, Id)>, } /// A group of panels: a header of tab strip and panel menu button, dragged by its empty part, over the active panel's @@ -626,7 +629,19 @@ impl Component for } let grip = cx.part_if_declared(GRIP).map(|grip| (grip.rect, crate::runtime::access::sub_node_id(cx.core.id, GRIP.into()))); let Reported { - picked, closed, picked_document, closed_documents, menu, item, commands, toggle_minimized, torn_off, drag_started, tabs, .. + picked, + closed, + picked_document, + closed_documents, + menu, + item, + commands, + toggle_minimized, + torn_off, + drag_started, + tabs, + overflow, + .. } = self.reported; DockGroupOutput { response: cx.response.clone(), @@ -642,6 +657,7 @@ impl Component for drag_started, tabs, grip, + overflow, } } } @@ -748,12 +764,13 @@ impl Container for // A press on the group's empty body focuses its panel, as in Photoshop; an app's own egui body keeps its presses. if surface_pressed && !self.host_body - && let Some((strip, _)) = &strip + && let Some((strip, _, _)) = &strip { focus::request(ui.ctx(), FocusTarget::Id(*strip)); } - if let Some((strip, tabs)) = &strip { + if let Some((strip, tabs, overflow)) = &strip { self.reported.tabs = tabs.iter().map(|(key, rect)| (*key, *rect, crate::contract::item_node(*strip, key))).collect(); + self.reported.overflow = *overflow; } let size = self.size; let (titles, reported) = (&self.panels, &mut self.reported); @@ -887,10 +904,13 @@ fn shown_tab(panels: &[PanelTitle], active: PanelKey) -> PanelKey { .unwrap_or(active) } -/// A group's tab strip with its tab insertion spots. Returns the strip's id and the rect of each tab it shows, which a -/// replay returns again, moved with the row. The panels' documents are tabs of the same strip after the panel tabs: one +/// What a group's tab row shows: the strip's id, each shown tab's rect and the overflow button with its node id. +type TabRowShown = (Id, Vec<(PanelKey, Rect)>, Option<(Rect, Id)>); + +/// A group's tab strip with its tab insertion spots. Returns the strip's id, the rect of each tab it shows and the +/// overflow button with its node id, which a replay returns again, moved with the row. The panels' documents are tabs of the same strip after the panel tabs: one /// fit, one overflow menu and one keyboard order for both. Only panel tabs drag and take tab insertions. -fn tab_row(row: &mut TabRow<'_, P>, ui: &mut Ui) -> (Id, Vec<(PanelKey, Rect)>) { +fn tab_row(row: &mut TabRow<'_, P>, ui: &mut Ui) -> TabRowShown { let env = crate::runtime::env::Env::of(ui); let name = Label::from(env.words::().panels.as_str().to_owned()); let rtl = env.direction.is_rtl(); @@ -977,7 +997,7 @@ fn tab_row(row: &mu if strip.empty_double { row.sent.send(TabEvent::EmptyDouble); } - (strip.response.response.id, strip.tab_rects) + (strip.response.response.id, strip.tab_rects, strip.overflow) } /// Registers the tab insertion spots of a group: the half of each shown tab nearer the start edge inserts before diff --git a/crates/ui-panels/src/docking/sources.rs b/crates/ui-panels/src/docking/sources.rs index 5b07725d9..1399c147b 100644 --- a/crates/ui-panels/src/docking/sources.rs +++ b/crates/ui-panels/src/docking/sources.rs @@ -1,6 +1,6 @@ -//! The places a dock area drew in a pass where a press starts a dock gesture: tabs, group bars, a floating window's -//! grip and resize grips, and the dividers. A host names them for its own automation (an element id per source) and -//! reads which one holds key focus by the source's node id. +//! The places a dock area drew in a pass where a press starts a dock gesture: tabs, group bars, a tab strip's overflow +//! button, a floating window's grip and resize grips, and the dividers. A host names them for its own automation (an +//! element id per source) and reads which one holds key focus by the source's node id. use crate::runtime::windows::ResizeEdge; use egui::{Id, Rect, ViewportId}; @@ -38,6 +38,9 @@ pub enum SourceKind

{ Document(P, u64), /// The bar a group is dragged by, named by the group's first panel. GroupBar(P), + /// The overflow button of a group's tab strip, named by the group's first panel: a click opens the menu of the tabs + /// that do not fit. Only while some tabs do not fit. + Overflow(P), /// The band a floating window is moved by, named by the window's first panel. WindowGrip(P), /// A grip a floating window is resized by, named by the window's first panel, with the edge or corner it moves. diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 1f19d184f..ad4a69010 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -1332,6 +1332,9 @@ impl Pass<'_, P> { }; let tabs = output.tabs.iter().filter_map(|(key, rect, node)| Some(DockSource::new(kind_of(*key)?, *rect, *node))); self.report.sources.extend(tabs); + if let Some((rect, node)) = output.overflow { + self.report.sources.push(DockSource::new(SourceKind::Overflow(anchor.clone()), rect, node)); + } if let Some((rect, node)) = output.grip { self.report.sources.push(DockSource::new(SourceKind::GroupBar(anchor.clone()), rect, node)); } diff --git a/crates/ui-patterns/tests/it/docking/sources.rs b/crates/ui-patterns/tests/it/docking/sources.rs index 623e906f1..d68e5cd2b 100644 --- a/crates/ui-patterns/tests/it/docking/sources.rs +++ b/crates/ui-patterns/tests/it/docking/sources.rs @@ -4,10 +4,11 @@ use super::Numbered; use craft_behavior::Axis; use craft_behavior::dock::{Column, DockEdge, Floating, Group, Layout, Node, SplitSize, StackEntry, Workspace}; -use craft_ui::contract::{Bind, BodyCx, Tracked}; +use craft_ui::contract::{Bind, BodyCx, Role, Tracked}; use craft_ui::docking::{DividerKind, DockConfig, DockPanels, DockSource, HidePanels, PanelKey, SourceKind}; use craft_ui::patterns::dock::DockArea; use craft_ui::runtime::env::{BodyMode, ShellCx, ShellEntry, WindowKey}; +use craft_ui::testing::access::NodeKey; use craft_ui::testing::{Fixture, trial}; use egui::{Pos2, Rect, Ui, Vec2}; use std::cell::RefCell; @@ -166,3 +167,31 @@ fn each_stack_section_reports_its_panels_tab() { let tabs = panels(&reported.borrow(), |kind| if let SourceKind::Tab(panel) = kind { Some(*panel) } else { None }); assert_eq!(tabs, [UPPER, LOWER], "{:?}", reported.borrow()); } + +/// A group whose tabs do not fit reports its strip's overflow button, named by the group's first panel, under the id of +/// the button's node and where a click opens the menu of the hidden tabs; groups whose tabs fit report none. +#[trial] +fn a_group_whose_tabs_do_not_fit_reports_its_overflow_button() { + const PANELS: [usize; 6] = [11, 12, 13, 14, 15, 16]; + let reported: Rc>>> = Rc::default(); + let seen = Rc::clone(&reported); + let mut narrow = Fixture::new(move |ui| { + let mut workspace = Arc::new(Workspace::new(Layout::new(Some(Node::tabs(PANELS.to_vec(), 0)), Vec::new()))); + let specs = Tracked::new(Numbered); + let mut bodies = Bodies; + *seen.borrow_mut() = DockArea::new("Overflow", Bind::bound(&mut workspace), &specs, &mut bodies, DockConfig::default()).show(ui).sources; + }); + narrow.room(Vec2::new(160.0, 300.0)).settle(); + let overflow: Vec> = + reported.borrow().iter().filter(|source| matches!(source.kind, SourceKind::Overflow(_))).cloned().collect(); + let kinds: Vec> = overflow.iter().map(|source| source.kind.clone()).collect(); + assert_eq!(kinds, vec![SourceKind::Overflow(PANELS[0])], "one overflow button, named by the group's first panel"); + let more = narrow.by_label("More tabs").expect("the strip's overflow button shows"); + assert_eq!(more.node, NodeKey::of(overflow[0].id), "the source's id is the button's node"); + assert!(narrow.by_role(Role::MENU_ITEM).is_empty(), "no menu is open yet"); + narrow.click_at(overflow[0].rect.center()).settle(); + assert!(!narrow.by_role(Role::MENU_ITEM).is_empty(), "a click on the source's rect opens the menu of the hidden tabs"); + + let (_wide, wide) = fixture(None, None); + assert!(wide.borrow().iter().all(|source| !matches!(source.kind, SourceKind::Overflow(_))), "groups whose tabs fit report no overflow button"); +} diff --git a/crates/ui-widgets/src/tabs/strip.rs b/crates/ui-widgets/src/tabs/strip.rs index ce8278c47..e8379d281 100644 --- a/crates/ui-widgets/src/tabs/strip.rs +++ b/crates/ui-widgets/src/tabs/strip.rs @@ -99,6 +99,8 @@ pub struct TabStripOutput { pub empty_drag: bool, /// The second press of a double click went down on the strip's empty room this pass. pub empty_double: bool, + /// The overflow button, when some tabs do not fit: its rect in screen space and the id of its accessibility node. + pub overflow: Option<(Rect, Id)>, } impl Outcome for TabStripOutput { @@ -988,6 +990,7 @@ impl Component f fn finish(self, mut cx: Cx<'_, Self>) -> TabStripOutput { let tab_rects = self.tab_rects(&cx); + let overflow = self.more.map(|rect| (rect, crate::runtime::access::sub_node_id(cx.core.id, OVERFLOW.into()))); let TabStrip { picked, torn, wheeled, empty_drag, empty_double, can_close, kind, .. } = self; let mut response = cx.collection_response(); let (mut closed, mut menu) = (Vec::new(), None); @@ -1010,7 +1013,7 @@ impl Component f mods: craft_keymap::Mods::NONE, })); response.events = kept; - TabStripOutput { response, closed, menu, picked, torn_off: torn, tab_rects, empty_drag, empty_double } + TabStripOutput { response, closed, menu, picked, torn_off: torn, tab_rects, empty_drag, empty_double, overflow } } } diff --git a/docs/ui-docking.md b/docs/ui-docking.md index c9dd4314d..b9e587024 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -82,7 +82,7 @@ Props: `hide` (`HidePanels::None`, `All` or `Except`), `maximized`, `auto_collap A panel in a column collapsed to icons shows in its flyout (`Layout::opens_in_flyout`). The host opens and closes it by writing the `flyout` binding, not the layout: `WindowMenuRows` checks such a panel's row while its flyout is open (`WindowMenuRows::flyout`) and reports a pick in `WindowMenuRowsOutput::flyout`. -`DockAreaOutput` holds the `actions` taken, the bodies' `requested` actions, the `events` for the host, the `focused` and `picked` panels, the `pressed` panel (the shown panel of the group whose body the primary press went down in, whatever took it, so a host whose bodies are its own egui code knows the panel clicked into), the gesture `sources` (a panel tab, a document tab, a group bar, window grips, dividers), `edit`, `float_space`, `columns`, the OS `windows` the floating windows showed in (by a panel of each), `window_files` (one `WindowFiles` per drop on a floating OS window: the shown panel of the group under the drop, the first group's for a drop on the title row, and the files), and `error`: an `InvalidGeometry` when the workspace fails `validate`, in which case the area draws nothing. +`DockAreaOutput` holds the `actions` taken, the bodies' `requested` actions, the `events` for the host, the `focused` and `picked` panels, the `pressed` panel (the shown panel of the group whose body the primary press went down in, whatever took it, so a host whose bodies are its own egui code knows the panel clicked into), the gesture `sources` (a panel tab, a document tab, a group bar, a tab strip's overflow button, window grips, dividers), `edit`, `float_space`, `columns`, the OS `windows` the floating windows showed in (by a panel of each), `window_files` (one `WindowFiles` per drop on a floating OS window: the shown panel of the group under the drop, the first group's for a drop on the title row, and the files), and `error`: an `InvalidGeometry` when the workspace fails `validate`, in which case the area draws nothing. The host handles these `DockEvent`s: