From 4b7937c270042ecaa6e442fc267cf0c798c3ab28 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 22:06:49 -0500 Subject: [PATCH] Tile: quiet check box (Checkbox::quiet) and an outlined selected band tile (trials) --- crates/ui-widgets/src/choice/check.rs | 26 ++++++++++++++++++-- crates/ui-widgets/src/choice/mod.rs | 16 ++++++++++++ crates/ui-widgets/src/tile_grid/tile.rs | 11 ++++++--- crates/ui-widgets/tests/it/label/hit.rs | 16 ++++++++++++ crates/ui-widgets/tests/it/tile_grid/tile.rs | 19 +++++++++++++- 5 files changed, 82 insertions(+), 6 deletions(-) diff --git a/crates/ui-widgets/src/choice/check.rs b/crates/ui-widgets/src/choice/check.rs index 2412a8bc1..dba0385bb 100644 --- a/crates/ui-widgets/src/choice/check.rs +++ b/crates/ui-widgets/src/choice/check.rs @@ -23,18 +23,31 @@ pub struct CheckboxStyle { side: f32, } +/// The side of a quiet check box, against the icon side. +const QUIET_SIDE: f32 = 0.6; + /// A check box over a bool; a `Mixed` binding shows the mixed state and a click makes it checked. #[derive(crate::contract::Component)] pub struct Checkbox<'a> { #[common] common: Common, value: Bind<'a, bool>, + /// A small, dark box with a plain white mark in place of the accent fill: the check of a thumbnail tile, which + /// sits over a picture and must not outweigh it. + #[style_key] + quiet: bool, } impl<'a> Checkbox<'a> { /// A check box of `value`. pub fn new(value: Bind<'a, bool>) -> Self { - Checkbox { common: Common::new(), value } + Checkbox { common: Common::new(), value, quiet: false } + } + + /// A small, dark box with a plain mark, for a check that sits over a picture (a thumbnail tile's). + pub fn quiet(mut self, on: bool) -> Self { + self.quiet = on; + self } } @@ -46,8 +59,17 @@ impl Component for Checkbox<'_> { type Style = CheckboxStyle; type Output = EditResponse; - fn style(cx: &StyleCx<'_>, _: CheckboxStyleKey) -> CheckboxStyle { + fn style(cx: &StyleCx<'_>, key: CheckboxStyleKey) -> CheckboxStyle { let control = cx.control(); + if key.quiet { + return CheckboxStyle { + metrics: Metrics::new().min_size(Vec2::new(0.0, control.icon * QUIET_SIDE)), + focus: cx.focus_look(), + well: super::quiet_indicator(cx, cx.surface(SurfaceKind::Well).radius), + mark: super::quiet_mark(cx), + side: control.icon * QUIET_SIDE, + }; + } CheckboxStyle { metrics: Metrics::new().min_size(Vec2::new(0.0, control.height)), focus: cx.focus_look(), diff --git a/crates/ui-widgets/src/choice/mod.rs b/crates/ui-widgets/src/choice/mod.rs index a4c0dc47b..1f92fa0c3 100644 --- a/crates/ui-widgets/src/choice/mod.rs +++ b/crates/ui-widgets/src/choice/mod.rs @@ -33,6 +33,22 @@ fn indicator(cx: &crate::style::StyleCx<'_>, radius: egui::CornerRadius) -> crat look } +/// The well of a quiet check box: dark in either state with a thin faint edge, so the box reads over a picture and +/// its checked state is told by the mark alone. +fn quiet_indicator(cx: &crate::style::StyleCx<'_>, radius: egui::CornerRadius) -> crate::style::SurfaceLook { + use crate::style::{SurfaceKind, SurfaceLook}; + use craft_theme::{Stateful, States}; + let dark = cx.color(cx.tokens.color.surface.scrim); + let edge = cx.color(cx.tokens.color.text.faint); + let fill = Stateful::new(dark).off(States::new(dark, dark, dark, dark)); + SurfaceLook::new(fill).kind(SurfaceKind::Sunken).radius(radius).border(Stateful::new(edge), cx.tokens.stroke.thin) +} + +/// The mark of a quiet check box: the ink that reads on an accent, in both states. +fn quiet_mark(cx: &crate::style::StyleCx<'_>) -> craft_theme::Stateful { + craft_theme::Stateful::new(cx.color(cx.tokens.color.text.on_accent)) +} + /// The fill of a check box, radio button or switch track while off: the sunken well, the state layer's press fill while /// pressed, and the panel while disabled, so a disabled off control is an empty frame. fn well(cx: &crate::style::StyleCx<'_>) -> craft_theme::Stateful { diff --git a/crates/ui-widgets/src/tile_grid/tile.rs b/crates/ui-widgets/src/tile_grid/tile.rs index daa9c1fb6..5f7577b8b 100644 --- a/crates/ui-widgets/src/tile_grid/tile.rs +++ b/crates/ui-widgets/src/tile_grid/tile.rs @@ -782,7 +782,12 @@ impl Component for Tile<'_> { Stateful::new(0.0).on(States::new(thin, thin, thin, thin)).when(Flags::CURRENT, thin) }; let radius = UiTokens::corner(tokens.shape.radius.control); - let surface = SurfaceLook::new(fill).radius(radius); + let mut surface = SurfaceLook::new(fill).radius(radius); + if key.action_place == TileActionPlace::Band { + // A band tile has no ring round its picture: the selected tile is outlined as a whole. + let (line, accent) = (c(clear), c(colors.accent.solid)); + surface = surface.border(Stateful::new(line).on(States::new(accent, accent, accent, accent)), tokens.stroke.medium); + } let surface = if key.card { surface.kind(SurfaceKind::Raised) } else { surface }; // A selected tile's name reads in the normal ink: the selection is the ring, not a fill under the name. let normal = c(text.normal); @@ -867,7 +872,7 @@ impl Component for Tile<'_> { let words = cx.words::(); self.pills = self.corner_badges(&words, &cx.env.units()); let faces = Faces { - check: cx.face(Checkbox::new(Bind::given(Mixed::Same(false)))), + check: cx.face(Checkbox::new(Bind::given(Mixed::Same(false))).quiet(true)), stars: cx.face(Rating::new(Bind::given(0u8), STARS).compact(true)), pill: cx.face(Badge::new("0")).y, action: self @@ -1089,7 +1094,7 @@ impl Component for Tile<'_> { ToggleState::Mixed => Mixed::Mixed, state => Mixed::Same(state == ToggleState::On), }; - ui.face(CHECK, Checkbox::new(Bind::given(value))); + ui.face(CHECK, Checkbox::new(Bind::given(value)).quiet(true)); } self.paint_caption(ui, cx, &placed); self.caption_rect = match self.caption { diff --git a/crates/ui-widgets/tests/it/label/hit.rs b/crates/ui-widgets/tests/it/label/hit.rs index 9d34ee55d..e1946b444 100644 --- a/crates/ui-widgets/tests/it/label/hit.rs +++ b/crates/ui-widgets/tests/it/label/hit.rs @@ -145,3 +145,19 @@ fn arrows_move_through_a_radio_group_without_picking_and_enter_picks() { frames.frame(vec![], &mut show); assert_eq!(picked.get(), 2, "Enter picks the focused radio"); } + +/// A quiet check box (a thumbnail tile's) is a smaller box than the standard one. +#[trial] +fn a_quiet_check_box_is_smaller_than_the_standard_one() { + let side = |quiet: bool| { + let mut frames = Frames::new(); + let shown = Cell::new(Rect::NOTHING); + let mut show = |ui: &mut Ui| { + shown.set(in_region(ui, REGION, |ui| Checkbox::new(Bind::given(false)).quiet(quiet).show(ui).response.rect)); + }; + frames.frame(vec![], &mut show); + frames.frame(vec![], &mut show); + shown.get().height() + }; + assert!(side(true) < side(false), "quiet {} against standard {}", side(true), side(false)); +} diff --git a/crates/ui-widgets/tests/it/tile_grid/tile.rs b/crates/ui-widgets/tests/it/tile_grid/tile.rs index f11c2cd0e..91751f65f 100644 --- a/crates/ui-widgets/tests/it/tile_grid/tile.rs +++ b/crates/ui-widgets/tests/it/tile_grid/tile.rs @@ -2,7 +2,7 @@ //! shows are apart and inside the tile, and a part that does not fit is left out. use craft_theme::Srgba; -use craft_ui::contract::Show as _; +use craft_ui::contract::{Props as _, Show as _}; use craft_ui::testing::layout::in_region; use craft_ui::testing::{Frames, trial}; use craft_ui::tile_grid::{BadgeVisibility, Tile, TileFlag}; @@ -133,3 +133,20 @@ fn a_named_action_is_exposed_by_its_own_name_while_its_tile_shows_it() { assert!(fixture.by_label(NAMES[1]).is_some(), "the hovered tile's action is named for its tile"); assert!(fixture.by_label(NAMES[0]).is_none(), "the other tile's action stays hidden"); } + +/// A selected band tile (the organize grid's) is outlined as a whole: it paints an edge that the same tile unselected +/// does not. +#[trial] +fn a_selected_band_tile_is_outlined() { + let edges = |selected: bool| { + let mut frames = Frames::new(); + let mut shapes = Vec::new(); + for _ in 0..3 { + shapes = frames.frame_shapes(|ui| { + Tile::new("Page 1").action_place(craft_ui::tile_grid::TileActionPlace::Band).selected(selected).show(ui); + }); + } + shapes.iter().filter(|shape| matches!(shape, Shape::Rect(rect) if rect.stroke.width > 0.0 && rect.stroke.color.a() > 0)).count() + }; + assert!(edges(true) > edges(false), "selected {} against unselected {}", edges(true), edges(false)); +}