diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index c9494966b4..c13364ab10 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -10,7 +10,8 @@ pub(crate) mod stories; use super::headers::Outline; use super::layout::{ - Around, ArrangeSpacing, GridLayout, Slot, TailRow, TileGroup, Tiling, arrange, aspects_of, columns_in, fit_candidates, normalize_columns, slot_at, + Around, ArrangeSpacing, GridLayout, HeaderScroll, Slot, TailRow, TileGroup, Tiling, arrange, aspects_of, columns_in, fit_candidates, + normalize_columns, slot_at, }; use super::tile::AroundPicture; use super::{CaptionPlace, CardText, PictureEdge, Tile, TileActionPlace, TilePartEvent, TileZoom, ZoomStep}; @@ -262,7 +263,8 @@ const WHEEL_SHARE: f32 = 1.0 / 3.0; /// app holds, or one the grid steps itself through a binding (`GridZoom`). A card is the /// picture plus what the tile adds around it, whatever the layout. Pictures are `aspect` wide over high; with /// `justified` the tiles keep their own aspects (the source's `ItemSource::size_hint` as `SizeHint::Aspect`) and fill -/// rows. `groups` put headers over runs of tiles; a header stays pinned at the top while its group scrolls. The grid +/// rows. `groups` put headers over runs of tiles; a header stays pinned at the top while its group scrolls, unless +/// `header_scroll` has the headers scroll with their tiles. The grid /// decides where every tile's caption goes and whether the cards hold a detail line. #[derive(crate::contract::Component, crate::contract::Props)] #[component(collection, probe(TileGrid<'static, usize>))] @@ -348,6 +350,9 @@ pub struct TileGrid<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { /// Group headers show a disclosure that opens and closes their group. #[prop(flag)] collapsible: bool, + /// Whether a titled header pins at the top while its group scrolls, or scrolls with its tiles. + #[prop] + header_scroll: HeaderScroll, /// Full-width rows after the tiles, below a divider: actions such as "Create preset". A click or Enter on one /// reports `CollectionEvent::Activate` with its key. #[prop] @@ -496,6 +501,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> { picture_edge: PictureEdge::Open, groups: &[], collapsible: false, + header_scroll: HeaderScroll::Pinned, tail: &[], rating_keys: RatingKeys::None, checks: false, @@ -678,6 +684,8 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> { }; let mut arrangement = arrange(&aspects, &groups, width, tiling, spacing, around); arrangement.add_tail(self.tail.len(), tail_height, width, spacing); + // A rule has nothing to pin. + arrangement.header_scroll = if self.group_heads == GroupHeads::Rule { HeaderScroll::WithTiles } else { self.header_scroll }; if fitted { let occupied = columns.unwrap_or(1) as f32 * (side + around.width()) + columns.unwrap_or(1).saturating_sub(1) as f32 * spacing.gap; let by = vec2((width - occupied).max(0.0) / 2.0, (room.y - arrangement.height).max(0.0) / 2.0); @@ -838,8 +846,7 @@ impl Component for TileGrid<'_, K> let Some(arrangement) = self.laid.borrow().as_ref().and_then(|layout| layout.arrangement().cloned()) else { return }; let (view, offset, rtl) = (cx.content_rect, cx.offset(), cx.flow.is_rtl()); let rule = self.group_heads == GroupHeads::Rule; - // A rule has nothing to pin. - let pinned = if rule { None } else { arrangement.pinned(offset.y as f32) }; + let pinned = arrangement.pinned(offset.y as f32); let shift = view.min.to_vec2() - vec2(offset.x as f32, offset.y as f32); if self.can_move_groups && !rule { self.group_gaps.extend(arrangement.headers.iter().map(|header| { diff --git a/crates/ui-widgets/src/tile_grid/grid/stories.rs b/crates/ui-widgets/src/tile_grid/grid/stories.rs index 6410fd8bf5..b5c95073ff 100644 --- a/crates/ui-widgets/src/tile_grid/grid/stories.rs +++ b/crates/ui-widgets/src/tile_grid/grid/stories.rs @@ -279,12 +279,13 @@ fn tile_grid_band_actions(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { StoryOutput::from(out).readout(readout) } -/// Slides in one column with their numbers at the start, each picture framed as a slide on the pane, the second -/// selected with a rounded ring; every third slide has a mark under its number. +/// Slides in one column with their numbers at the start, each picture framed as a slide on the pane, the fourth +/// selected with a rounded ring that stands off its picture; every third slide has a mark under its number, and the +/// fifth is hidden, its picture faded into the pane. #[story(TileGrid<'static, usize>, covers = [], drive = Drive::Never)] fn tile_grid_framed_pictures(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let pictures = StoryPictures::of(ui.ctx()); - let selection = data.value("selection", Selection::single(1usize)); + let selection = data.value("selection", Selection::single(3usize)); let grid = TileGrid::new("Slides") .column_rule(ColumnRule::Exactly(1)) .caption(CaptionPlace::Start) @@ -292,12 +293,27 @@ fn tile_grid_framed_pictures(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { .picture_edge(PictureEdge::Framed) .selection(Bind::bound(selection)); grid.show_items(ui, &Photos(PAGES), &mut |key, _| { - let tile = Tile::new(format!("{}", key + 1)).thumb(ThumbAspect::new(16, 9), pictures.thumb(*key as u64)); - if key % 3 == 0 { tile.mark(TileMark::new(IconId::new("star_filled"), "Has animation")) } else { tile } + let mut tile = Tile::new(format!("{}", key + 1)).thumb(ThumbAspect::new(16, 9), pictures.thumb(*key as u64)); + if key % 3 == 0 { + tile = tile.mark(TileMark::new(IconId::new("star_filled"), "Has animation")); + } + if *key == 4 { tile.hidden() } else { tile } }) .into() } +/// Sections of slides whose headers scroll away with their slides instead of pinning at the top. +#[story(TileGrid<'static, usize>, covers = [], drive = Drive::Never)] +fn tile_grid_headers_scroll_with_tiles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let groups = [ + TileGroup::new(GROUP_KEYS[0], 0, 12, "Introduction (12)"), + TileGroup::new(GROUP_KEYS[1], 12, 8, "Science (8)"), + TileGroup::new(GROUP_KEYS[2], 20, 10, "In the Field (10)"), + ]; + let slides = TileGrid::new("Slides").column_rule(ColumnRule::Exactly(1)).groups(&groups).header_scroll(super::HeaderScroll::WithTiles); + grid(ui, data, slides, 30, 1.0).into() +} + /// Photos of the insert gap story. const GAP_PHOTOS: usize = 12; diff --git a/crates/ui-widgets/src/tile_grid/layout.rs b/crates/ui-widgets/src/tile_grid/layout.rs index 0ea3b27ef1..01457c44f2 100644 --- a/crates/ui-widgets/src/tile_grid/layout.rs +++ b/crates/ui-widgets/src/tile_grid/layout.rs @@ -272,6 +272,19 @@ pub struct TileArrangement { pub tails: Vec, /// The whole height. pub height: f32, + /// Whether a header pins at the top while its group scrolls. + pub header_scroll: HeaderScroll, +} + +/// How a group header scrolls. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::contract::MemoProps)] +#[non_exhaustive] +pub enum HeaderScroll { + /// The header of the group crossing the top edge stays pinned there, until the next header lifts it out. + #[default] + Pinned, + /// Every header scrolls with its tiles, as a section title in a slide pane does. + WithTiles, } impl TileArrangement { @@ -348,8 +361,11 @@ impl TileArrangement { } /// The header pinned at the top of a view scrolled to `top`, and where it stands: the header of the group whose - /// tiles cross the top edge, lifted out by the next header. + /// tiles cross the top edge, lifted out by the next header. None while the headers scroll with their tiles. pub fn pinned(&self, top: f32) -> Option<(usize, Rect)> { + if self.header_scroll == HeaderScroll::WithTiles { + return None; + } let group = self.group_at(top)?; let header = *self.headers.get(group)?; if header.top() >= top { diff --git a/crates/ui-widgets/src/tile_grid/mod.rs b/crates/ui-widgets/src/tile_grid/mod.rs index 851de2e217..e987323bda 100644 --- a/crates/ui-widgets/src/tile_grid/mod.rs +++ b/crates/ui-widgets/src/tile_grid/mod.rs @@ -19,7 +19,7 @@ use craft_theme::variant::Tone; pub use fit::fit_columns; pub use grid::{ColumnRule, GridEvent, GridZoom, GroupHeads, RatingKeys, TileGrid, TileGridOutput, TileGridStyle}; -pub use layout::{Around, ArrangeSpacing, GridLayout, TailRow, TileArrangement, TileGroup, TileRow, Tiling, arrange, aspects_of}; +pub use layout::{Around, ArrangeSpacing, GridLayout, HeaderScroll, TailRow, TileArrangement, TileGroup, TileRow, Tiling, arrange, aspects_of}; pub use slider::{ThumbnailSlider, ThumbnailSliderStyle, TileZoom, ZoomStep}; pub use tile::{GlyphLayout, PictureEdge, StackLook, Tile, TileActionPlace, TileOutput, TilePartEvent, TileStyle}; pub use words::TileWords; diff --git a/crates/ui-widgets/src/tile_grid/tile.rs b/crates/ui-widgets/src/tile_grid/tile.rs index 077d15fdbd..3da650cd82 100644 --- a/crates/ui-widgets/src/tile_grid/tile.rs +++ b/crates/ui-widgets/src/tile_grid/tile.rs @@ -17,7 +17,7 @@ use crate::contract::{ }; use crate::display::{Badge, Picture}; use crate::list::{RowThumb, ThumbAspect, ThumbPaint, ToggleState}; -use crate::primitives::{ContentPainterCx, HAlign, IconSpec, PaintShape, StrokeWidth, TextRun, Wrap}; +use crate::primitives::{ContentPainterCx, DataWidth, HAlign, IconSpec, PaintShape, StrokePlace, StrokeWidth, TextRun, Wrap}; use crate::runtime::commands::CommandRef; use crate::runtime::env::{Label, Units}; use crate::style::{ @@ -71,7 +71,10 @@ pub enum PictureEdge { #[default] Open, /// Every picture framed, as a slide or a page lying on the pane: a thin frame line at rest, a thin muted ring under - /// the pointer, and an accent ring with rounded corners while selected or current. + /// the pointer, and an accent ring with rounded corners that stands a tight gap off the picture while selected or + /// current. The ring lies on the pane, not against the picture, so it needs no halo. A dimmed, rejected or hidden + /// picture fades into the surface under the grid instead of going under the scrim, and the marks keep their faint + /// ink while the tile is selected. Framed, } @@ -308,7 +311,10 @@ pub struct TileStyle { /// The fill of a picture that shows nothing yet, and of one on a sunken surface, where the sunken fill would vanish. placeholder: StyleColor, placeholder_on_sunken: StyleColor, + /// The veil over a dimmed, rejected or hidden picture, and over one on a sunken surface: the scrim, or for a + /// framed picture the surface under the grid, which the picture fades into. dim: StyleColor, + dim_on_sunken: StyleColor, /// The ring outside the picture: the accent when selected or current, the muted ink under the pointer, the frame /// line at rest round a framed picture. ring: Stateful, @@ -317,6 +323,8 @@ pub struct TileStyle { ring_width: Stateful, /// The corner radius of the ring and its halo: rounded while a framed picture is selected or current, else square. ring_radius: Stateful, + /// How far the ring stands off the picture: a tight gap while a framed picture is selected or current, else none. + ring_gap: Stateful, /// The halo outside a selected ring, so it reads on any background. halo: StyleColor, /// The halo's width: thin when selected or current, none otherwise. @@ -927,7 +935,9 @@ impl Component for Tile<'_> { }; let round = if framed { tokens.shape.radius.sm } else { 0.0 }; let ring_radius = Stateful::new(0.0).on(States::new(round, round, round, round)).when(Flags::CURRENT, round); - let halo_width = if key.action_place == TileActionPlace::Band { + let gap = if framed { tokens.space.gap.tight } else { 0.0 }; + let ring_gap = Stateful::new(0.0).on(States::new(gap, gap, gap, gap)).when(Flags::CURRENT, gap); + let halo_width = if key.action_place == TileActionPlace::Band || framed { Stateful::new(0.0) } else { Stateful::new(0.0).on(States::new(thin, thin, thin, thin)).when(Flags::CURRENT, thin) @@ -968,7 +978,7 @@ impl Component for Tile<'_> { detail: TextLook::new(TypeRole::Caption, ink(c(if key.card { text.muted } else { text.faint }))), band_text: TextLook::new(TypeRole::Caption, fixed(text.on_status)).on(fixed(colors.status.bad.solid)), band_icon: IconLook::new(sizes.glyph, fixed(text.on_status)).on(fixed(colors.status.bad.solid)), - mark: IconLook::new(sizes.mark, ink(c(text.faint))), + mark: IconLook::new(sizes.mark, if framed { fixed(text.faint) } else { ink(c(text.faint)) }), stars: on_bar(c(text.on_strong), tokens.size.icon.glyph_sm), picked: on_bar(cx.tone(Tone::Good), sizes.glyph), rejected: on_bar(cx.tone(Tone::Bad), sizes.glyph), @@ -976,10 +986,12 @@ impl Component for Tile<'_> { pill_icon: IconLook::new(sizes.glyph, pill.text.clone()).on(pill.fill.clone()), placeholder: c(colors.surface.sunken), placeholder_on_sunken: c(colors.surface.raised), - dim: c(colors.surface.scrim.faded(DIM_VEIL)), + dim: c(if framed { colors.surface.panel } else { colors.surface.scrim }.faded(DIM_VEIL)), + dim_on_sunken: c(if framed { colors.surface.sunken } else { colors.surface.scrim }.faded(DIM_VEIL)), ring, ring_width, ring_radius, + ring_gap, halo: c(colors.overlay.halo), halo_width, plate, @@ -1167,15 +1179,19 @@ impl Component for Tile<'_> { // A card's picture is the sunken surface, which the placeholder's fill matches. let placeholder = if !style.sizes.card && cx.env.surface() == SurfaceKind::Sunken { style.placeholder_on_sunken } else { style.placeholder }; if !self.flat_thumbnail { - // Filled from the outside in, under the picture, so the rings sit outside its edge. - let (ring, halo) = (cx.resolve(&style.ring_width), cx.resolve(&style.halo_width)); + // Stroked outside the edge, so the rings cover nothing of the picture and the gap between shows the surface. + let (ring, halo, gap) = (cx.resolve(&style.ring_width), cx.resolve(&style.halo_width), cx.resolve(&style.ring_gap)); let round = UiTokens::corner(cx.resolve(&style.ring_radius)); let draw = ui.draw(); + let outside = |inset: f32, width: f32, color: StyleColor| { + let edge = PaintShape::Rect(picture.expand(inset), round); + draw.stroke_placed(&edge, StrokePlace::Outside, DataWidth::points(width), color); + }; if halo > 0.0 { - draw.fill(&PaintShape::Rect(picture.expand(ring + halo), round), style.halo); + outside(gap + ring, halo, style.halo); } if ring > 0.0 { - draw.fill(&PaintShape::Rect(picture.expand(ring), round), cx.resolve(&style.ring)); + outside(gap, ring, cx.resolve(&style.ring)); } // A band tile's selection fill covers the whole tile, picture included: no well over it. if self.action_place != TileActionPlace::Band { @@ -1224,7 +1240,8 @@ impl Component for Tile<'_> { draw.icon(icon, &face.color(color)); } if self.dimmed || self.rejected || self.hidden { - draw.fill(&PaintShape::Rect(picture, flat), style.dim); + let veil = if cx.env.surface() == SurfaceKind::Sunken { style.dim_on_sunken } else { style.dim }; + draw.fill(&PaintShape::Rect(picture, flat), veil); } self.paint_range_and_scrub(&draw, cx, picture); } diff --git a/crates/ui-widgets/tests/it/tile_grid/grid.rs b/crates/ui-widgets/tests/it/tile_grid/grid.rs index c24b7883e8..e0ce2c68ac 100644 --- a/crates/ui-widgets/tests/it/tile_grid/grid.rs +++ b/crates/ui-widgets/tests/it/tile_grid/grid.rs @@ -11,7 +11,8 @@ use craft_ui::list::{ThumbAspect, ToggleState}; use craft_ui::runtime::env::Label; use craft_ui::testing::{Fixture, pointer}; use craft_ui::tile_grid::{ - Around, ArrangeSpacing, ColumnRule, GridEvent, GridZoom, GroupHeads, TailRow, Tile, TileGrid, TileGroup, TileZoom, Tiling, ZoomStep, arrange, + Around, ArrangeSpacing, ColumnRule, GridEvent, GridZoom, GroupHeads, HeaderScroll, TailRow, Tile, TileGrid, TileGroup, TileZoom, Tiling, + ZoomStep, arrange, }; use egui::{Key, Modifiers, Pos2, Rect, Vec2}; use std::cell::{Cell, RefCell}; @@ -109,6 +110,33 @@ fn the_output_names_each_shown_header_and_its_rect() { assert!(headers[0].1.bottom() <= tile(0).top() + EPS, "the first header lies above the first tile"); } +/// Scrolled to the end of a long group, its header stays pinned at the top of the view, unless the headers scroll with +/// their tiles, when it has left the view with the first tiles. +#[craft_ui::testing::trial] +fn a_header_that_scrolls_with_its_tiles_leaves_the_view() { + let shown = |scroll: HeaderScroll| { + let headers = Rc::new(RefCell::new(Vec::new())); + let held = headers.clone(); + let mut fixture = Fixture::new(move |ui| { + let keys: Vec = (0..12).collect(); + let source = keyed(&keys, |key: &usize| *key); + let groups = [TileGroup::new(100, 0, 12, "Morning")]; + let out = TileGrid::new("Library").column_rule(ColumnRule::Exactly(1)).groups(&groups).header_scroll(scroll).reveal(11).show_items( + ui, + &source, + &mut |key, _| Tile::new(format!("Tile {key}")), + ); + *held.borrow_mut() = out.headers; + }); + fixture.room(Vec2::new(200.0, 300.0)).settle(); + assert!(fixture.by_label("Tile 0").is_none_or(|tile| tile.rect.bottom() <= 0.0), "the grid scrolled past the first tile"); + let groups: Vec = headers.borrow().iter().map(|(group, _)| *group).collect(); + groups + }; + assert_eq!(shown(HeaderScroll::Pinned), vec![0], "a pinned header stays in view"); + assert!(shown(HeaderScroll::WithTiles).is_empty(), "a header that scrolls with its tiles leaves the view"); +} + /// The title edit goes through the section's F2 path and the real text field; rejected drafts never reach the host. #[craft_ui::testing::trial] fn a_renamed_group_header_reports_its_title_once() { diff --git a/crates/ui-widgets/tests/it/tile_grid/tile.rs b/crates/ui-widgets/tests/it/tile_grid/tile.rs index 77ba339110..3f11ed5ea6 100644 --- a/crates/ui-widgets/tests/it/tile_grid/tile.rs +++ b/crates/ui-widgets/tests/it/tile_grid/tile.rs @@ -156,29 +156,94 @@ fn a_selected_band_tile_is_outlined() { #[trial] fn a_framed_picture_has_an_edge_at_rest_and_a_rounded_selection_ring() { use craft_ui::tile_grid::PictureEdge; - let filled = |edge: PictureEdge, selected: bool| { - let mut frames = Frames::new(); - let mut shapes = Vec::new(); - for _ in 0..3 { - shapes = frames.frame_shapes(|ui| { - Tile::new("1").picture_edge(edge).selected(selected).show(ui); - }); - } - let mut rects: Vec<_> = shapes + let painted = |edge: PictureEdge, selected: bool| { + let mut rects: Vec<_> = tile_shapes(|| Tile::new("1").picture_edge(edge).selected(selected)) .into_iter() .filter_map(|shape| if let Shape::Rect(rect) = shape { Some(rect) } else { None }) - .filter(|rect| rect.fill.a() > 0) + .filter(|rect| rect.fill.a() > 0 || (rect.stroke.width > 0.0 && rect.stroke.color.a() > 0)) .collect(); - rects.sort_by(|a, b| (b.rect.area()).total_cmp(&a.rect.area())); + rects.sort_by(|a, b| b.visual_bounding_rect().area().total_cmp(&a.visual_bounding_rect().area())); rects }; - let (open, framed) = (filled(PictureEdge::Open, false), filled(PictureEdge::Framed, false)); - assert!(framed[0].rect.contains_rect(open[0].rect) && framed[0].rect != open[0].rect, "the frame lies round the picture at rest"); - let (open, framed) = (filled(PictureEdge::Open, true), filled(PictureEdge::Framed, true)); + let (open, framed) = (painted(PictureEdge::Open, false), painted(PictureEdge::Framed, false)); + let (open_bounds, framed_bounds) = (open[0].visual_bounding_rect(), framed[0].visual_bounding_rect()); + assert!(framed_bounds.contains_rect(open_bounds) && framed_bounds != open_bounds, "the frame lies round the picture at rest"); + let (open, framed) = (painted(PictureEdge::Open, true), painted(PictureEdge::Framed, true)); assert!(open[0].corner_radius == egui::CornerRadius::ZERO, "an open picture's ring is square"); assert!(framed[0].corner_radius != egui::CornerRadius::ZERO, "a framed picture's ring is rounded"); } +/// The shapes a lone tile paints once it has settled. +fn tile_shapes(tile: impl Fn() -> Tile<'static>) -> Vec { + let mut frames = Frames::new(); + let mut shapes = Vec::new(); + for _ in 0..3 { + shapes = frames.frame_shapes(|ui| { + tile().show(ui); + }); + } + shapes +} + +/// The picture of a lone tile (the placeholder that fills it) and the rings stroked round it, innermost first. +fn picture_and_rings(tile: impl Fn() -> Tile<'static>) -> (Rect, Vec) { + let rects: Vec<_> = tile_shapes(tile).into_iter().filter_map(|shape| if let Shape::Rect(rect) = shape { Some(rect) } else { None }).collect(); + let picture = + rects.iter().filter(|rect| rect.fill.a() > 0).map(|rect| rect.rect).max_by(|a, b| a.area().total_cmp(&b.area())).expect("the picture"); + let mut rings: Vec<_> = rects.into_iter().filter(|rect| rect.stroke.width > 0.0 && rect.stroke.color.a() > 0).collect(); + rings.sort_by(|a, b| a.rect.area().total_cmp(&b.rect.area())); + (picture, rings) +} + +/// A framed picture's selection ring stands off the picture, so the pane shows between them, and needs no halo; an +/// open picture's ring lies against the picture, with a halo so it reads on any picture. +#[trial] +fn a_framed_selection_ring_stands_off_the_picture_without_a_halo() { + use craft_ui::tile_grid::PictureEdge; + let (picture, open) = picture_and_rings(|| Tile::new("1").picture_edge(PictureEdge::Open).selected(true)); + assert_eq!(open.first().map(|ring| ring.rect), Some(picture), "an open ring lies against its picture"); + let (picture, framed) = picture_and_rings(|| Tile::new("1").picture_edge(PictureEdge::Framed).selected(true)); + let ring = framed.first().expect("a framed picture's ring").rect; + assert!(ring.contains_rect(picture) && ring.left() < picture.left() && ring.top() < picture.top(), "the ring {ring:?} stands off {picture:?}"); + assert!(framed.len() < open.len(), "a framed ring has no halo: {} rings against an open picture's {}", framed.len(), open.len()); +} + +/// A hidden framed picture fades into the surface under it, lighter than the scrim that veils an open one. +#[trial] +fn a_hidden_framed_picture_fades_instead_of_going_under_the_scrim() { + use craft_ui::tile_grid::PictureEdge; + let veil = |edge: PictureEdge| { + let shapes = tile_shapes(|| Tile::new("1").picture_edge(edge).hidden()); + let fills: Vec<_> = shapes.into_iter().filter_map(|shape| if let Shape::Rect(rect) = shape { Some(rect) } else { None }).collect(); + let picture = fills.iter().filter(|rect| rect.fill.a() > 0).map(|rect| rect.rect).max_by(|a, b| a.area().total_cmp(&b.area())); + let last = fills.iter().rev().find(|rect| Some(rect.rect) == picture && rect.fill.a() > 0).expect("the veil").fill; + let [r, g, b, _] = last.to_srgba_unmultiplied(); + u32::from(r) + u32::from(g) + u32::from(b) + }; + assert!(veil(PictureEdge::Framed) > veil(PictureEdge::Open), "the framed veil is lighter than the scrim"); +} + +/// A selected framed tile keeps its mark in the faint ink it has at rest; an open tile's mark takes the normal ink. +#[trial] +fn a_selected_framed_tiles_mark_keeps_its_faint_ink() { + use craft_behavior::IconId; + use craft_ui::tile_grid::{CaptionPlace, PictureEdge, TileMark}; + let mark = |edge: PictureEdge, selected: bool| { + tile_shapes(|| { + let mark = TileMark::new(IconId::new("star_filled"), "Has animation"); + Tile::new("1").caption(CaptionPlace::Start).picture_edge(edge).mark(mark).selected(selected) + }) + .into_iter() + .find_map(|shape| match shape { + Shape::Mesh(mesh) => mesh.vertices.iter().map(|vertex| vertex.color).find(|color| color.a() > 0), + _ => None, + }) + .expect("the mark is painted") + }; + assert_ne!(mark(PictureEdge::Open, true), mark(PictureEdge::Open, false), "an open tile's mark changes ink when selected"); + assert_eq!(mark(PictureEdge::Framed, true), mark(PictureEdge::Framed, false), "a framed tile's mark keeps its ink"); +} + /// A card of a preset centres its name; a card of a file sets it at the reading start. #[trial] fn card_text_places_the_name_centred_for_presets_and_at_the_start_for_files() {