menu gallery: the current tile is an accent.soft fill with a 1 pt accent.solid edge

The fill keeps the tile reading as current under the focus ring, as WordCraft v0.18.1 drew it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin BallandClaude Opus 5.5 committed 2026-11-25 23:42:31 +00:00
1 parent c47f6b8643
commit 4bc277f544
2 files changed
+67 -5

No files matched your search

+11 -5
View File
@@ -356,7 +356,7 @@ fn grid<K>(ui: &mut Ui, label: &Label, items: &[GalleryItem<'_, K>], current: Op
// ---------------------------------------------------------------------------------------------------------------
// The tile.
/// The style of a gallery tile: the accent outline while it is the current one.
/// The style of a gallery tile: the accent fill and edge while it is the current one.
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
#[non_exhaustive]
struct GalleryTileStyle {
@@ -366,9 +366,11 @@ struct GalleryTileStyle {
focus: FocusLook,
/// Between the tile's edge and its picture.
pad: f32,
/// The current tile's outline: `accent.solid`, unfilled, so the picture keeps its own background. Not
/// `accent.border`, which several themes pin translucent to read on a control's own fill: with no fill under it,
/// it falls under 3:1 on the ribbon.
/// The selection edge's width.
stroke: f32,
/// The current tile's fill: `accent.soft`, so the tile still reads as current under the focus ring.
fill: StyleColor,
/// The current tile's edge: `accent.solid`, not the translucent `accent.border`.
edge: StyleColor,
/// The ink of the item's name under the picture, in a captioned gallery.
caption: StyleColor,
@@ -441,6 +443,8 @@ impl Component for GalleryTile<'_> {
metrics: Metrics::new().padding(Insets::new(pad, pad, pad, pad)),
focus: cx.focus_look(),
pad,
stroke: cx.tokens.stroke.thin,
fill: cx.color(colors.accent.soft),
edge: cx.color(colors.accent.solid),
caption: cx.color(colors.text.normal),
gap: cx.tokens.space.gap.tight,
@@ -468,7 +472,9 @@ impl Component for GalleryTile<'_> {
}
if self.selected {
let outer = area.expand(cx.style.pad);
ui.draw().stroke(&PaintShape::Rect(outer, CornerRadius::ZERO), craft_ui::primitives::StrokeWidth::Thin, cx.style.edge);
let draw = ui.draw();
draw.fill(&PaintShape::Rect(outer, CornerRadius::ZERO), cx.style.edge);
draw.fill(&PaintShape::Rect(outer.shrink(cx.style.stroke), CornerRadius::ZERO), cx.style.fill);
}
// A captioned tile keeps the picture's height at the top and shows the name in the rest under it.
let (area, caption) = match self.caption {
+56
View File
@@ -191,3 +191,59 @@ fn a_framed_gallery_paints_sunken_well_and_stepper_track() {
seen.iter().find(|(rect, fill)| *fill == panel && rect.contains_rect(column.shrink(1.0)) && gallery_rect.contains_rect(*rect));
assert!(stepper_track.is_some(), "a panel fill covers the stepper track column {column:?}: {seen:?}");
}
/// The current tile paints an `accent.soft` fill inside a 1 pt `accent.solid` edge, and a non-current tile paints
/// neither; the fill stays under the focus ring, so a focused current tile still reads as current.
/// This holds in light and dark, at standard and high contrast.
#[trial]
fn the_current_tile_paints_an_accent_fill_and_edge_even_when_focused() {
use craft_theme::{Contrast, Mode};
use craft_ui::runtime::env::Env;
use egui::Color32;
fn rects(shapes: &[egui::Shape], out: &mut Vec<(Rect, Color32)>) {
for shape in shapes {
match shape {
egui::Shape::Vec(inner) => rects(inner, out),
egui::Shape::Rect(rect) => out.push((rect.rect, rect.fill)),
_ => {}
}
}
}
for (mode, contrast) in
[(Mode::Light, Contrast::Standard), (Mode::Dark, Contrast::Standard), (Mode::Light, Contrast::High), (Mode::Dark, Contrast::High)]
{
let colors = Rc::new(Cell::new((craft_theme::Rgba::TRANSPARENT, craft_theme::Rgba::TRANSPARENT)));
let held = colors.clone();
let mut fixture = Fixture::new(move |ui| {
let accent = Env::of(ui).tokens.tokens().color.accent;
held.set((accent.soft, accent.solid));
let paint = |_: &ContentPainterCx, _: Rect| {};
let items: Vec<GalleryItem<'_, usize>> =
(0..3).map(|at| GalleryItem { key: at, label: Label::from(format!("Tile {at}")), face: GalleryFace::Paint(&paint) }).collect();
let _ = Gallery::new("Styles", &items, Some(&0)).tiles(3, 3).show(ui);
});
fixture.theme(mode, contrast).settle();
let (soft, solid) = colors.get();
let [fill, edge] = [soft, solid].map(|c| {
let [r, g, b, a] = c.0;
Color32::from_rgba_unmultiplied(r, g, b, a)
});
assert_ne!(fill, edge, "{mode:?} {contrast:?}: the fill and the edge are different colours");
let [current, other] = ["Tile 0", "Tile 1"].map(|name| fixture.by_label(name).map_or(Rect::NOTHING, |tile| tile.rect));
let painted = |fixture: &mut Fixture, color: Color32, tile: Rect| {
let mut seen = Vec::new();
rects(&fixture.frame_shapes(), &mut seen);
seen.iter().any(|(rect, c)| *c == color && rect.intersects(tile) && tile.expand(8.0).contains_rect(*rect))
};
for color in [fill, edge] {
assert!(painted(&mut fixture, color, current), "{mode:?} {contrast:?}: the current tile paints {color:?}");
assert!(!painted(&mut fixture, color, other), "{mode:?} {contrast:?}: another tile does not paint {color:?}");
}
fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle();
assert!(fixture.focused().is_some(), "{mode:?} {contrast:?}: Tab focused the gallery");
assert!(painted(&mut fixture, fill, current), "{mode:?} {contrast:?}: the focused current tile keeps its fill");
}
}