From 7cbba1e35890b776365bf902203d89df0595575f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 28 Nov 2026 06:43:00 +0000 Subject: [PATCH 1/2] ribbon: a card body stands a margin in from the region's edges, the row padded inside it Co-Authored-By: Claude Opus 5.5 --- crates/menu/src/ribbon.rs | 20 +++++++++++----- crates/menu/tests/it/ribbon.rs | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index 2e13fda468..14cfb7a4ff 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -508,8 +508,8 @@ struct RegionStyle { edge: craft_ui::style::StyleColor, /// The panel radius of a card body. radius: f32, - /// The regular padding around a card body. - inset: f32, + /// The outer region's room around a card (the card's margin), and the inner region's room inside it. + inset: craft_behavior::Insets, } /// What a row region reports. @@ -570,7 +570,14 @@ impl Component for Region { fn style(cx: &StyleCx<'_>, key: RegionStyleKey) -> RegionStyle { let body = 3.0 * cx.control().height + 2.0 * cx.tokens.space.gap.row; let title = cx.tokens.typography.caption.line_height; - let inset = if key.senses && cx.env::().body == RibbonBody::Card { cx.tokens.space.pad.regular } else { 0.0 }; + // A card stands a regular pad in from the window's sides and its own foot, and a tight gap under the tab strip; + // the row stands a chip pad in from the card's top and foot. + let space = &cx.tokens.space; + let inset = match (cx.env::().body, key.senses) { + (RibbonBody::Card, true) => craft_behavior::Insets::new(space.pad.regular, space.pad.regular, space.gap.tight, space.pad.regular), + (RibbonBody::Card, false) => craft_behavior::Insets::vertical(space.pad.chip), + _ => craft_behavior::Insets::default(), + }; let mut style = RegionStyle { metrics: Metrics::new(), slide: cx.tokens.motion.slide as f32, @@ -588,7 +595,7 @@ impl Component for Region { inset, edge: cx.color(cx.tokens.color.line.divider), }; - style.metrics = style.metrics.padding(craft_behavior::Insets::uniform(style.inset)); + style.metrics = style.metrics.padding(style.inset); style } @@ -596,12 +603,13 @@ impl Component for Region { if self.senses { Sense::SURFACE | Sense::CONTEXT_CLICK } else { Sense::empty() } } - /// The outer region paints the band's rules or the card's rounded edge around the chosen surface. + /// The outer region paints the band's rules, or the card's rounded edge around the chosen surface inside its margin. fn paint(&mut self, ui: &mut craft_ui::contract::PaintUi<'_>, cx: &Cx<'_, Self>) { let Some(fill) = cx.style.fill.filter(|_| self.senses) else { return }; let draw = ui.draw(); if cx.env.get::().body == RibbonBody::Card { - let shape = craft_ui::primitives::PaintShape::Rect(cx.rect, craft_ui::style::UiTokens::corner(cx.style.radius)); + let card = craft_behavior::Flow::new(cx.rect, cx.env.direction().is_rtl()).inset(cx.style.inset); + let shape = craft_ui::primitives::PaintShape::Rect(card, craft_ui::style::UiTokens::corner(cx.style.radius)); draw.fill(&shape, fill); draw.stroke(&shape, craft_ui::primitives::StrokeWidth::Thin, cx.style.edge); return; diff --git a/crates/menu/tests/it/ribbon.rs b/crates/menu/tests/it/ribbon.rs index 3fe3a6e506..cc4e451686 100644 --- a/crates/menu/tests/it/ribbon.rs +++ b/crates/menu/tests/it/ribbon.rs @@ -428,6 +428,50 @@ fn an_untitled_ribbon_draws_no_group_titles_and_keeps_their_names() { } } +/// A card body is a raised card that stands in from the ribbon's sides, below its tab strip, and holds every group: +/// painted over the whole row, it met the window's edges and read as a flat band. +#[trial] +fn a_card_body_stands_in_from_the_ribbons_edges_and_holds_its_groups() { + fn fills(shapes: &[egui::Shape], out: &mut Vec<(egui::Rect, egui::Color32)>) { + for shape in shapes { + match shape { + egui::Shape::Vec(inner) => fills(inner, out), + egui::Shape::Rect(rect) => out.push((rect.rect, rect.fill)), + _ => {} + } + } + } + + for direction in [Direction::Ltr, Direction::Rtl] { + let seen = Rc::new(Cell::new((egui::Rect::NOTHING, egui::Color32::TRANSPARENT))); + let held = seen.clone(); + let mut fixture = Fixture::new(move |ui| { + let [r, g, b, a] = Env::of(ui).tokens.tokens().color.surface.raised.0; + held.set((ui.max_rect(), egui::Color32::from_rgba_unmultiplied(r, g, b, a))); + let tabs = [RibbonTab::new(0_usize, "Home")]; + let look = RibbonLook::new(30, 17).row(22).body(craft_menu::ribbon::RibbonBody::Card); + Ribbon::new("Ribbon", &tabs, Bind::given(0_usize)).look(look).show(ui, |row, _| { + group(row, "first", "First", &["One"]); + group(row, "second", "Second", &["Two"]); + }); + }); + fixture.direction(direction).room(vec2(900.0, 400.0)).motion(MotionMode::Reduced).settle(); + let (room, raised) = seen.get(); + let mut painted = Vec::new(); + fills(&fixture.frame_shapes(), &mut painted); + let groups = fixture.by_label("First").expect("the first group").rect.union(fixture.by_label("Second").expect("the second group").rect); + let card = painted + .iter() + .filter(|(rect, fill)| *fill == raised && rect.contains_rect(groups)) + .map(|(rect, _)| *rect) + .next() + .unwrap_or_else(|| panic!("a raised card holds the groups {groups:?}: {painted:?}")); + let tab = fixture.by_label("Home").expect("the tab").rect; + assert!(card.left() > room.left() && card.right() < room.right(), "the card stands in from both sides of {room:?}: {card:?}"); + assert!(card.top() >= tab.bottom(), "the card sits below the tab strip {tab:?}: {card:?}"); + } +} + /// Each tab keeps its own offset, including while hidden. The query includes a pending chevron jump before /// layout applies it, and rerunning the input frame does not apply the click again. #[trial] From 1ea150b08e91f7527f1d35e1c82ec47372e72e20 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 28 Nov 2026 07:15:09 +0000 Subject: [PATCH 2/2] ribbon: a card body takes the surface radius, as a card inset on the window surface does The panel radius is the docked panels'; an app that rounds its ribbon card through it rounded its docked panes too. Co-Authored-By: Claude Opus 5.5 --- crates/menu/src/ribbon.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index 14cfb7a4ff..9eb9d545bd 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -506,7 +506,7 @@ struct RegionStyle { fill: Option, /// The divider ink around a card. edge: craft_ui::style::StyleColor, - /// The panel radius of a card body. + /// The corner radius of a card body: a surface's, as a card standing inset on the window's surface takes. radius: f32, /// The outer region's room around a card (the card's margin), and the inner region's room inside it. inset: craft_behavior::Insets, @@ -591,7 +591,7 @@ impl Component for Region { RibbonBody::Card => Some(cx.color(cx.tokens.color.surface.raised)), _ => None, }, - radius: cx.tokens.shape.radius.panel, + radius: cx.tokens.shape.radius.surface, inset, edge: cx.color(cx.tokens.color.line.divider), };