From 2055375e6bc5ce3e3f024806dcdf156ed270fa79 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 00:15:34 +0000 Subject: [PATCH] fu2-ribbon: app batch 2 rulings (S-L418, S-L392, S-L360, S-L361, S-L363) Button keeps room for its widest text (room_for) and shows a rendered picture in the leading icon's place (picture). ShownRow reports the id its item is recorded under; the ribbon reports tab_ids from it and hosts its own context menu (context_menu body), so RibbonOutput::menu and RibbonMenuRequest::opener go. Stories and trials for each. Co-Authored-By: Claude Opus 5.5 --- crates/menu/src/ribbon.rs | 145 +++++++++++++++--- crates/menu/src/ribbon/stories.rs | 36 ++++- crates/menu/tests/it/keytips.rs | 58 ++++++- crates/menu/tests/it/ribbon.rs | 57 +++++-- .../src/contract/collection/response.rs | 7 +- .../ui-contract/src/contract/items/hooks.rs | 2 +- crates/ui-widgets/src/buttons/button.rs | 74 +++++++-- crates/ui-widgets/src/buttons/face.rs | 82 +++++++--- crates/ui-widgets/src/buttons/split_button.rs | 1 + crates/ui-widgets/src/buttons/stories.rs | 30 +++- .../ui-widgets/src/buttons/toggle_button.rs | 1 + crates/ui-widgets/src/choice/segmented.rs | 1 + crates/ui-widgets/src/menu/bar.rs | 2 + crates/ui-widgets/tests/it/buttons.rs | 59 ++++++- 14 files changed, 467 insertions(+), 88 deletions(-) diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index 8a5705ca9e..80d7dd666a 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -14,13 +14,16 @@ use std::sync::Arc; use craft_behavior::{CanvasTransform, EditEvent, IconId, Metrics, Mixed, SelectionChange, Sense, keyed}; use craft_keymap::CommandRef; use craft_ui::buttons::IconButton; +use craft_ui::contract::overlay::Anchor; use craft_ui::contract::{ - Access, Bind, CollectionEvent, Common, Component, Container, ContainerProps, Cx, NoValue, Outcome, Props as _, Role, Scroll, - Show as _, ShowCollection as _, ShowContainer as _, Sizing, clicked, scroll_step, + Access, Bind, BodyCx, CollectionEvent, Common, Component, Container, ContainerProps, Cx, NoValue, Outcome, Props as _, Role, + Scroll, Show as _, ShowCollection as _, ShowContainer as _, Sizing, Trigger, clicked, scroll_step, }; use craft_ui::layout_components::Row; +use craft_ui::menu::Menu; use craft_ui::runtime::env::{Env, Label}; use craft_ui::runtime::inspect; +use craft_ui::runtime::memory::with_session; use craft_ui::runtime::motion::{Animate as _, spec}; use craft_ui::style::{ComponentStyle, StyleCx}; use craft_ui::tabs::{StripEnd, Tab, TabKind, TabRole, TabStrip, TabStripOutput}; @@ -36,15 +39,22 @@ craft_ui::words! { struct RibbonWords { scroll_left: "ribbon.scrollLeft" = "Scroll left"; scroll_right: "ribbon.scrollRight" = "Scroll right"; + context_menu: "ribbon.contextMenu" = "Ribbon menu"; } } /// The ribbon: a [`TabKind::Ribbon`](craft_ui::tabs::TabKind) strip over a scrolling group row, -/// with minimise and context requests. The strip and the row show inside one inspected region +/// with minimise and a context menu. The strip and the row show inside one inspected region /// (`inspect::record`), whose record ([`RibbonOutput::controls`]) gives each control's rect and -/// command. On a tab change the group row slides in from the side on which the new tab lies -/// relative to the old one (mirrored in right-to-left), through one `Tween`; with reduce motion the -/// new content shows at rest. +/// command, and [`RibbonOutput::tab_ids`] says which recorded element is which tab. On a tab change +/// the group row slides in from the side on which the new tab lies relative to the old one +/// (mirrored in right-to-left), through one `Tween`; with reduce motion the new content shows at +/// rest. +/// +/// A context request (a secondary click, the Menu key or Shift+F10) on a tab, a control or the row's +/// background opens the ribbon's own menu, whose rows the app's [`context_menu`](Ribbon::context_menu) +/// body shows for that request. The ribbon holds the request while the menu is open, and focus goes back +/// where it was when the menu closes by key. #[must_use = "show the ribbon with `show`"] #[derive(craft_ui::contract::Pattern)] #[pattern(probe(Ribbon<'static, usize>))] @@ -54,12 +64,22 @@ pub struct Ribbon<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> { shown: Bind<'a, T>, trailing: &'a [StripEnd<'a>], minimised: Option>, + /// The body of the context menu: the rows for the request that opened it. + context_menu: Option<&'a mut dyn FnMut(&mut Ui, &RibbonMenuRequest, &mut BodyCx<'_>)>, } impl<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> Ribbon<'a, T> { /// A ribbon named `label` over `tabs`, showing the tab `shown` binds. pub fn new(label: impl Into