diff --git a/crates/ui-widgets/src/tile_grid/tile.rs b/crates/ui-widgets/src/tile_grid/tile.rs index 35b1ef4451..ea8d5dc081 100644 --- a/crates/ui-widgets/src/tile_grid/tile.rs +++ b/crates/ui-widgets/src/tile_grid/tile.rs @@ -27,15 +27,13 @@ use crate::style::{ use craft_behavior::{AccessAction, AccessData, Flow, IconId, Insets, Metrics, Mixed, NavShape, PartKey, PressPhase, Proposal, Roving, Sense}; use craft_keymap::Mods; use craft_theme::variant::{Emphasis, Tone}; -use craft_theme::{Rgba, Srgba, Stateful, States, TypeRole, Variant, over}; +use craft_theme::{Opacity, Rgba, Srgba, Stateful, States, TypeRole, Variant, over}; use egui::{Color32, CornerRadius, Pos2, Rect, Response, Vec2}; /// Stars a rating has. const STARS: u8 = 5; /// The share of the scrim's opacity that veils a dimmed, rejected or hidden tile's picture. const DIM_VEIL: f32 = 0.45; -/// The share of the scrim's opacity that a page card on a tile (`CardText::PageTile`) lays over the surface at rest. -const PAGE_TILE_VEIL: f32 = 0.2; /// What a tile's own parts report, besides what the collection reads from the pointer. #[derive(Clone, Debug, PartialEq)] @@ -847,7 +845,7 @@ impl Component for Tile<'_> { Stateful::new(rest).off(States::new(rest, hover, pressed, rest)).on(States::new(hover, hover, pressed, hover)) } else if key.card && key.card_text == CardText::PageTile { // A page card on a tile: a veil of the scrim darkens the surface under it at rest. - let (rest, hover, pressed) = (c(colors.surface.scrim.faded(PAGE_TILE_VEIL)), c(state.hover), c(state.pressed)); + let (rest, hover, pressed) = (c(colors.surface.scrim.faded(Opacity::TINT)), c(state.hover), c(state.pressed)); Stateful::new(rest).off(States::new(rest, hover, pressed, rest)).on(States::new(hover, hover, pressed, hover)) } else if key.card { let raised = colors.surface.raised; diff --git a/crates/ui-widgets/tests/it/tile_grid/tile.rs b/crates/ui-widgets/tests/it/tile_grid/tile.rs index 100068ff5a..1ad364e595 100644 --- a/crates/ui-widgets/tests/it/tile_grid/tile.rs +++ b/crates/ui-widgets/tests/it/tile_grid/tile.rs @@ -1,7 +1,7 @@ //! A tile's badge bar never draws one part over another: at every width the stars, the flag and the colour dot it //! shows are apart and inside the tile, and a part that does not fit is left out. -use craft_theme::Srgba; +use craft_theme::{Opacity, Srgba}; use craft_ui::contract::{Props as _, Show as _}; use craft_ui::testing::layout::in_region; use craft_ui::testing::{Frames, trial}; @@ -413,8 +413,8 @@ fn a_page_card_wraps_its_name_and_sets_the_detail_under_it() { } } -/// A `PageTile` card paints a veil of the scrim over the whole card at rest, and a `Page` card paints no fill of its -/// own. +/// A `PageTile` card paints a veil of the scrim at the theme's tint opacity over the whole card at rest, and a `Page` +/// card paints no fill of its own. #[trial] fn a_page_tile_card_rests_on_a_tile_and_a_page_card_does_not() { use craft_ui::runtime::env::Env; @@ -442,8 +442,9 @@ fn a_page_tile_card_rests_on_a_tile_and_a_page_card_does_not() { (scrim, covering) }; let (scrim, covering) = shown(CardText::PageTile); - let veil = |fill: &Color32| fill.a() > 0 && fill.a() < scrim.a() && fill.to_opaque() == scrim.to_opaque(); - assert!(covering.iter().any(veil), "a page tile card rests on a veil of the scrim {scrim:?}: {covering:?}"); + let tint = (f32::from(scrim.a()) * Opacity::TINT + 0.5) as u8; + let veil = |fill: &Color32| fill.a() == tint && fill.to_opaque() == scrim.to_opaque(); + assert!(covering.iter().any(veil), "a page tile card rests on a veil of the scrim {scrim:?} at alpha {tint}: {covering:?}"); let (_, covering) = shown(CardText::Page); assert!(covering.iter().all(|fill| *fill == Color32::TRANSPARENT), "a page card lies flat, with no fill of its own: {covering:?}"); }