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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE
This commit is contained in:
Martin Ball
2026-11-20 03:04:24 +00:00
co-authored by Claude Opus 5.5
parent 2b7e9dc96b
commit ace9547545
5 changed files with 37 additions and 4 deletions
+8 -1
View File
@@ -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 (&current, minimised) {
(Some(key), false) => Some(show_row(ui, id, tabs, key, (icons, &launcher), &mut body)),
+2 -2
View File
@@ -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(
+13 -1
View File
@@ -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.
+12
View File
@@ -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<f32>,
}
/// 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<K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> 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::<crate::buttons::RibbonLook>();
(ribbon && look.underline > 0).then_some(f32::from(look.underline))
},
}
}
+2
View File
@@ -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::<crate::buttons::RibbonLook>().tab_ink => ink(colors.text.normal, colors.accent.text),
(true, _) => ink(colors.text.muted, colors.accent.text),
_ => ink(colors.text.muted, colors.text.normal),
};