diff --git a/crates/menu/src/shortcuts/view/table.rs b/crates/menu/src/shortcuts/view/table.rs index 562c0c74e..1cab972d9 100644 --- a/crates/menu/src/shortcuts/view/table.rs +++ b/crates/menu/src/shortcuts/view/table.rs @@ -1,20 +1,27 @@ //! The command table: command and shortcut columns over the lines `rows` builds, group headers that open and //! close, and rows whose shortcut chips, add button and restore button are children of the row. +//! +//! A group header is a section row of the collection, which takes its press, keys and AccessKit node; the table paints +//! its look, a heading row with the disclosure triangle, over the row. use std::borrow::Cow; use craft_behavior::{ - ColumnKey, ColumnWidth, DisplayOrder, Flow, Insets, ItemSource, Metrics, Proposal, Selection, SelectionChange, Sense, SpanLayout, + ColumnKey, ColumnWidth, DisplayOrder, Flow, Insets, ItemSource, Metrics, PartKey, Proposal, Selection, SelectionChange, Sense, SpanLayout, }; use craft_keymap::chord::Chord; use craft_keymap::keymap::{Binding, MAX_BINDINGS}; use craft_ui::buttons::IconButton; use craft_ui::contract::{ - Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, ColumnSpec, Common, Component, ContainerProps, Cx, ItemOutput, - MeasureCx, Outcome, PaintUi, Pointer as _, Props as _, Role, SelectMode, ShowCollection as _, Sizing, Styled as _, clicked, + Access, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, ColumnSpec, Common, Component, ContainerProps, Cx, + Focus as _, ItemOutput, MeasureCx, Meta as _, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, Role, RowState, SelectMode, + ShowCollection as _, Sizing, Styled as _, clicked, }; +use craft_ui::controls::disclosure::Disclosure; use craft_ui::display::{Elide, Icon, Kbd, Shade, Text}; +use craft_ui::list::{ListRow, ListRowStyle}; use craft_ui::primitives::{IconSpec, Span, TextRun}; +use craft_ui::runtime::env::Label; use craft_ui::style::FocusLook; use craft_ui::style::{ComponentStyle, Ink, Stateful, StyleCx, TextLook, TypeRole}; use egui::{Pos2, Rect, Response, Ui, Vec2}; @@ -30,6 +37,10 @@ const SHORTCUT: ColumnKey = ColumnKey::new("shortcut"); /// buttons, and the command column takes the rest. const SHORTCUT_MOST: f32 = 0.4; const PATH_SEPARATOR: &str = " \u{203a} "; +/// The look of a group header, over its section row; the index is the header's line. +const HEADER: PartKey = PartKey::new("group_header"); +/// The disclosure triangle in a group header's disclosure column; the index is the header's line. +const HEADER_DISCLOSURE: PartKey = PartKey::new("group_disclosure"); /// What a row reports besides what the collection reads from its pointer input. #[derive(Clone, Debug, PartialEq)] @@ -89,12 +100,29 @@ impl DisplayOrder for Lines<'_> { impl ItemSource for Lines<'_> {} -/// The style of the table: no look of its own. -#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] +/// The style of the table: the look of its group headers. +#[derive(Clone, Debug, PartialEq, ComponentStyle)] #[non_exhaustive] pub(crate) struct ShortcutTableStyle { #[style(metrics)] metrics: Metrics, + /// A group header: a heading row, which places the disclosure the table declares. + header: ListRowStyle, +} + +/// A group header in view this pass. +#[derive(Clone, Copy, Debug)] +struct PlacedHeader { + /// The header's line. + at: usize, + /// The header row has a disclosure column. + disclosure: bool, +} + +/// The look of the group header `name`: a heading row with the group's disclosure, which the table declares and +/// paints. +fn header_row(name: &str, open: bool) -> ListRow<'static> { + ListRow::new(name.to_owned()).heading().node(false).group(open).disclosure_by_host() } /// A table of commands with their shortcuts. @@ -113,16 +141,25 @@ pub(crate) struct ShortcutTable<'a> { /// Scrolls this line into view once. #[prop] reveal: Option, + /// The lines the rows show, for the group headers the table paints. + lines: &'a [Line], + /// The group headers in view this pass. + headers: Vec, + /// Where the rows show this pass: the headers paint inside it, clear of the column header. + rows_view: Option, } impl<'a> ShortcutTable<'a> { - fn new(label: impl Into, columns: Vec) -> Self { + fn new(label: impl Into