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