look-chrome: a menu end item of a tab strip shows the menu chevron

StripEnd::menu's full face ends with DisclosureGlyph::menu_button(), as every
button that opens a menu does (WordCraft's Editing item). Trial
a_menu_end_item_shows_the_menu_chevron; story tab_strip_ribbon_end_buttons
shows framed end items (two outlined, one accent).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin Ball
2026-11-19 13:31:40 +00:00
co-authored by Claude Opus 5.5
parent a54108ab1e
commit d9bcc7f542
3 changed files with 51 additions and 2 deletions
+2 -2
View File
@@ -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()),
}
}
@@ -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.
+37
View File
@@ -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<CommandRef>; 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<usize> = (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.