From ace9547545d01cddded4eed2f4f86c9da0573b14 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Fri, 20 Nov 2026 02:41:37 +0000 Subject: [PATCH] Ribbon look: tabs rest in the text colour over a bar underline (RibbonLook::tabs); the story shows the whole look Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE --- crates/menu/src/ribbon.rs | 9 ++++++++- crates/menu/src/ribbon/stories.rs | 4 ++-- crates/ui-widgets/src/buttons/mod.rs | 14 +++++++++++++- crates/ui-widgets/src/tabs/strip.rs | 12 ++++++++++++ crates/ui-widgets/src/tabs/tab.rs | 2 ++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index bf666180c..b9b1f235b 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -158,7 +158,14 @@ impl<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> Ribbon<'a, T> { if let Some(key) = current.clone() { strip = strip.shown(key); } - strip.show_items(ui, &source, &mut |key: &T, _| Tab::new(label_of(key)).role(role_of(key))) + // The look reaches the strip too: its tabs' ink and underline (`RibbonLook::tabs`). + craft_ui::runtime::env::with_env( + ui, + |overrides| { + overrides.values.set(icons); + }, + |ui| strip.show_items(ui, &source, &mut |key: &T, _| Tab::new(label_of(key)).role(role_of(key))), + ) }); let region = match (¤t, minimised) { (Some(key), false) => Some(show_row(ui, id, tabs, key, (icons, &launcher), &mut body)), diff --git a/crates/menu/src/ribbon/stories.rs b/crates/menu/src/ribbon/stories.rs index 63d1d48e7..bca6ba786 100644 --- a/crates/menu/src/ribbon/stories.rs +++ b/crates/menu/src/ribbon/stories.rs @@ -40,7 +40,7 @@ struct Setup { rtl: bool, /// The ribbon has a context menu. menu: bool, - /// The groups draw their icons at the sides an app sets (`Ribbon::icons`), with the app's launcher glyph. + /// The ribbon takes an app look (`Ribbon::look`): icon sides, menu arrows, row height, tab ink and underline. app_icons: bool, } @@ -83,7 +83,7 @@ fn show(ui: &mut Ui, data: &mut StoryData, setup: Setup) -> StoryOutput { ribbon = ribbon.context_menu(&mut rows); } if setup.app_icons { - ribbon = ribbon.look(RibbonLook::new(32, 17)).launcher_icon(IconId::new("chevron_down")); + ribbon = ribbon.look(RibbonLook::new(32, 17).arrow(10).row(20).tabs(3)).launcher_icon(IconId::new("chevron_down")); } let direction = if setup.rtl { Direction::Rtl } else { Env::of(ui).direction }; let out = with_env( diff --git a/crates/ui-widgets/src/buttons/mod.rs b/crates/ui-widgets/src/buttons/mod.rs index 954516997..413f0f4ce 100644 --- a/crates/ui-widgets/src/buttons/mod.rs +++ b/crates/ui-widgets/src/buttons/mod.rs @@ -88,12 +88,24 @@ pub struct RibbonLook { /// The height of a non-stacked button, so three of them, a tight gap apart, fill the ribbon's body (the old /// ribbon's 22-point pitch); 0 keeps the control's height. pub row: u8, + /// Whether a ribbon strip's tabs rest in the normal text colour, as the old ribbon's did, not the muted one. + pub tab_ink: bool, + /// The height of a ribbon strip's underline under the shown tab; 0 keeps the thick stroke. + pub underline: u8, } impl RibbonLook { /// Stacked icons `large` points square and the others `small`; 0 keeps the framework's side. pub const fn new(large: u8, small: u8) -> Self { - RibbonLook { large, small, arrow: 0, row: 0 } + RibbonLook { large, small, arrow: 0, row: 0, tab_ink: false, underline: 0 } + } + + /// The strip's tabs in the normal text colour at rest, and its underline `underline` points high (0 keeps the + /// thick stroke). + pub const fn tabs(mut self, underline: u8) -> Self { + self.tab_ink = true; + self.underline = underline; + self } /// Non-stacked buttons `row` points high; 0 keeps the control's height. diff --git a/crates/ui-widgets/src/tabs/strip.rs b/crates/ui-widgets/src/tabs/strip.rs index 1a0bd46d9..c0a608996 100644 --- a/crates/ui-widgets/src/tabs/strip.rs +++ b/crates/ui-widgets/src/tabs/strip.rs @@ -124,6 +124,9 @@ pub struct TabStripStyle { /// How far in from each side of the shown tab the underline starts: the tab's padding less half the stroke, so /// it runs just past the label at both ends, as the old ribbon drew it. underline_side: f32, + /// The underline's height where a ribbon look sets one (`RibbonLook::tabs`), a bar at the row's bottom; the thick + /// stroke otherwise. + underline_height: Option, } /// Where the fit put one end item: its position in `TabStrip::trailing`, its distance from the start edge, its width @@ -687,6 +690,11 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> TabStri let width = cx.anim("underline_width", width, spec::MOVE); let side = cx.style.underline_side.min(width / 2.0).max(0.0); let rect = Flow::new(cx.core.content_rect, cx.flow.is_rtl()).span(start + side, width - 2.0 * side); + if let Some(height) = cx.style.underline_height { + let bar = Rect::from_min_max(Pos2::new(rect.left(), rect.bottom() - height), rect.right_bottom()); + ui.draw().fill(&PaintShape::Rect(bar, egui::CornerRadius::ZERO), cx.style.underline); + return; + } let y = rect.bottom() - cx.style.underline_inset; ui.draw().stroke(&PaintShape::Path(vec![Pos2::new(rect.left(), y), Pos2::new(rect.right(), y)]), StrokeWidth::Thick, cx.style.underline); } @@ -735,6 +743,10 @@ impl Component f underline: cx.color(tokens.color.accent.solid), underline_inset: tokens.stroke.thick / 2.0, underline_side: side, + underline_height: { + let look = cx.env::(); + (ribbon && look.underline > 0).then_some(f32::from(look.underline)) + }, } } diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 3d8b33869..7e10f8a8b 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -343,6 +343,8 @@ impl Component for Tab<'_> { }; let label_ink = match (ribbon, key.role) { (true, TabRole::Contextual) => ink(colors.accent.text, colors.accent.text), + // A ribbon look may rest its tabs in the normal text colour (`RibbonLook::tabs`). + (true, _) if cx.env::().tab_ink => ink(colors.text.normal, colors.accent.text), (true, _) => ink(colors.text.muted, colors.accent.text), _ => ink(colors.text.muted, colors.text.normal), };