diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index 6e427f9ed..8a5705ca9 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -3,24 +3,42 @@ mod gallery; mod group; mod plan; +#[cfg(feature = "screen-testing")] +mod stories; +use std::borrow::Cow; use std::fmt::Debug; use std::hash::Hash; -use std::marker::PhantomData; use std::sync::Arc; +use craft_behavior::{CanvasTransform, EditEvent, IconId, Metrics, Mixed, SelectionChange, Sense, keyed}; use craft_keymap::CommandRef; -use craft_ui::contract::Bind; -use craft_ui::runtime::env::Label; +use craft_ui::buttons::IconButton; +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, +}; +use craft_ui::layout_components::Row; +use craft_ui::runtime::env::{Env, Label}; use craft_ui::runtime::inspect; -use craft_ui::tabs::{StripEnd, TabRole}; -use egui::{Id, Pos2, Rect, Ui}; +use craft_ui::runtime::motion::{Animate as _, spec}; +use craft_ui::style::{ComponentStyle, StyleCx}; +use craft_ui::tabs::{StripEnd, Tab, TabKind, TabRole, TabStrip, TabStripOutput}; +use egui::{Id, Pos2, Rect, Response, Ui, Vec2, vec2}; pub use craft_ui::buttons::GroupLevel; pub use gallery::{Gallery, GalleryFace, GalleryItem, GalleryMore, GalleryOutput}; pub use group::RibbonGroup; pub use plan::{GroupWidths, plan}; +craft_ui::words! { + /// The words of the ribbon's own controls. + struct RibbonWords { + scroll_left: "ribbon.scrollLeft" = "Scroll left"; + scroll_right: "ribbon.scrollRight" = "Scroll right"; + } +} + /// 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 /// (`inspect::record`), whose record ([`RibbonOutput::controls`]) gives each control's rect and @@ -28,58 +46,213 @@ pub use plan::{GroupWidths, plan}; /// relative to the old one (mirrored in right-to-left), through one `Tween`; with reduce motion the /// new content shows at rest. #[must_use = "show the ribbon with `show`"] +#[derive(craft_ui::contract::Pattern)] +#[pattern(probe(Ribbon<'static, usize>))] pub struct Ribbon<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> { - stub: PhantomData<(&'a (), T)>, + label: Label, + tabs: &'a [RibbonTab], + shown: Bind<'a, T>, + trailing: &'a [StripEnd<'a>], + minimised: Option>, } 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