diff --git a/crates/ui-widgets/src/tabs/strip/end.rs b/crates/ui-widgets/src/tabs/strip/end.rs index 4c21c10af..53c7374c4 100644 --- a/crates/ui-widgets/src/tabs/strip/end.rs +++ b/crates/ui-widgets/src/tabs/strip/end.rs @@ -73,12 +73,12 @@ impl<'a> StripEnd<'a> { self.command_ref().is_none_or(|command| cx.resolve_command(command.clone()).is_none_or(|resolved| resolved.enabled)) } - /// The face with the label beside the icon. + /// The face with the label beside the icon; a menu item's ends with the chevron of a button that opens a menu. fn full_face(&self) -> Button<'a> { let face = Button::new(self.label.clone()).icon(self.icon.clone()).variant(self.variant); match self.command_ref() { Some(command) => face.command(command.clone()).label(self.label.clone()), - None => face, + None => face.trailing_icon(crate::controls::disclosure::DisclosureGlyph::menu_button()), } } diff --git a/crates/ui-widgets/src/tabs/strip/stories.rs b/crates/ui-widgets/src/tabs/strip/stories.rs index 9b0775a36..69bf359d9 100644 --- a/crates/ui-widgets/src/tabs/strip/stories.rs +++ b/crates/ui-widgets/src/tabs/strip/stories.rs @@ -174,6 +174,18 @@ fn tab_strip_ribbon_end_items_narrow(ui: &mut Ui, data: &mut StoryData) -> Story }) } +/// End items as framed buttons: two outlined, the menu one with its chevron, and the last filled with the accent. +#[story(TabStrip<'static, usize>, covers = [], drive = Drive::Never)] +fn tab_strip_ribbon_end_buttons(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let rows = comment_rows(); + let items = [ + StripEnd::command("Comments", IconId::new("list").into(), EditCommands::Paste).variant(craft_theme::Variant::SECONDARY), + StripEnd::menu("Editing", IconId::new("list").into(), &rows).variant(craft_theme::Variant::SECONDARY), + StripEnd::command("Share", IconId::new("link").into(), EditCommands::Copy).variant(craft_theme::Variant::PRIMARY), + ]; + ribbon(ui, data, TabStrip::new("Ribbon").trailing(&items), &PLAIN) +} + /// The contextual tab is listed for the first frames and then dropped by the source: it fades out at its slot. The /// story reads the frame it is in rather than counting its runs, so a measuring run or a second pass of one frame /// lists the same tabs as the frame's other runs. diff --git a/crates/ui-widgets/tests/it/tabs.rs b/crates/ui-widgets/tests/it/tabs.rs index ae52004e8..ef4623d8d 100644 --- a/crates/ui-widgets/tests/it/tabs.rs +++ b/crates/ui-widgets/tests/it/tabs.rs @@ -537,6 +537,43 @@ fn end_items_drop_their_labels_before_a_tab_overflows() { assert!(kept, "a room keeps the contextual tab while a plain tab overflows"); } +/// The width of the one end item, named "Comments", of a ribbon strip in a wide room: a menu item when `menu`, else a +/// command item with the same label and icon. +fn comments_width(menu: bool) -> f32 { + use craft_behavior::IconId; + use craft_ui::contract::Entry; + use craft_ui::runtime::commands::{CommandRef, EditCommands}; + use craft_ui::tabs::StripEnd; + let rows: [Entry; 1] = [Entry::new(EditCommands::Paste.into(), "Show comments")]; + let item = if menu { + StripEnd::menu("Comments", IconId::new("list").into(), &rows) + } else { + StripEnd::command("Comments", IconId::new("list").into(), EditCommands::Copy) + }; + let items = [item]; + let mut frames = Frames::new(); + let mut show = |ui: &mut Ui| { + ui.set_max_width(2000.0); + let keys: Vec = (0..RIBBON.len()).collect(); + let source = keyed(&keys, |key: &usize| *key); + let strip = TabStrip::new("Ribbon").kind(TabKind::Ribbon).shown(1).roles(ribbon_role).trailing(&items); + strip.show_items(ui, &source, &mut |key, _| Tab::new(RIBBON[*key]).role(ribbon_role(key))); + }; + frames.idle(3, &mut show); + let tree = frames.tree(); + let buttons = tree.with_role(Role::BUTTON); + buttons.iter().find(|key| tree.name_of(**key) == Some("Comments")).and_then(|key| tree.bounds_of(*key)).map_or(0.0, |rect| rect.width()) +} + +/// An end item that opens a menu shows the chevron of a menu button after its label, as every button that opens a +/// menu does; an item that runs a command shows none, so the menu item is wider by the chevron. +#[trial] +fn a_menu_end_item_shows_the_menu_chevron() { + let (menu, command) = (comments_width(true), comments_width(false)); + assert!(command > 0.0, "the command item shows"); + assert!(menu > command + 4.0, "the menu item is wider by its chevron: {menu} against {command}"); +} + /// A contextual tab the source drops fades out at its slot: while it fades it has no node, a click on its slot /// selects nothing and the overflow menu does not list it; once the fade ends it is not painted. A frame of two /// passes paints the fade as one does. A contextual tab that comes back is hit from its first frame.