Merge branch 'port/deckcraft/look/fw-3' into port/deckcraft/area/framework

This commit is contained in:
Dylan M. Taylor committed 2026-11-28 08:03:13 +00:00
commit fa59fa863b
2 files changed
+60 -8

No files matched your search

+16 -8
View File
@@ -506,10 +506,10 @@ struct RegionStyle {
fill: Option<craft_ui::style::StyleColor>,
/// 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 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::<RibbonLook>().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::<RibbonLook>().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,
@@ -584,11 +591,11 @@ 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),
};
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::<RibbonLook>().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;
+44
View File
@@ -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]