diff --git a/crates/ui-contract/src/contract/items/hooks.rs b/crates/ui-contract/src/contract/items/hooks.rs index 350f042d1..752914b5d 100644 --- a/crates/ui-contract/src/contract/items/hooks.rs +++ b/crates/ui-contract/src/contract/items/hooks.rs @@ -433,10 +433,13 @@ impl ShapeHooks for ItemsHooks<'_, '_, C> { crate::runtime::commands::register_instance(&ctx, scope, id); } let child_size = comp.props(Internal::new()).child_size; + // The rows sit on the surface the collection paints, else on the one the collection sits on. + let own = surface.or_else(|| cx.style.surface().and_then(|look| look.kind_in(&cx.core.state))); let base_env = env.derive(|scoped| { scoped.extend_values(values); scoped.arena = Some(ArenaId::new(id)); scoped.size = child_size.unwrap_or(cx.core.resolved.size); + scoped.surface = SurfaceKind::under(own, scoped.surface); }); self.header.paint(ui, cx, env, id, rtl); let len = self.source.len(); @@ -717,8 +720,7 @@ impl ShapeHooks for ItemsHooks<'_, '_, C> { } if self.scrolls { let look = scroll_bar_look(&env.tokens, ScrollBarKind::Overlay); - // The rows blend into the surface the collection paints, else the one it sits on. - let own = surface.or_else(|| cx.style.surface().and_then(|look| look.kind_in(&cx.core.state))); + // The rows blend into the surface they sit on. let background = surface_style(&env.tokens, SurfaceKind::under(own, env.surface)).fill; let hidden = HiddenContent::new(self.content, rect.size(), Vec2::new(self.offset_x as f32, self.offset as f32), rtl); ui.painter().extend(ScrollBar::fades(&look, rect, hidden, background)); diff --git a/crates/ui-contract/src/runtime/env/view.rs b/crates/ui-contract/src/runtime/env/view.rs index d9b79229b..4a8e0155e 100644 --- a/crates/ui-contract/src/runtime/env/view.rs +++ b/crates/ui-contract/src/runtime/env/view.rs @@ -59,6 +59,12 @@ impl<'a> EnvView<'a> { self.scoped.inside_label.as_deref() } + /// The surface the component sits on: the innermost container or collection surface that paints a fill, else the + /// window's background. + pub fn surface(&self) -> crate::style::SurfaceKind { + self.scoped.surface + } + /// The flow direction: layout order, arrow keys and roving. pub fn direction(&self) -> Direction { self.scoped.direction diff --git a/crates/ui-widgets/src/tile_grid/tile.rs b/crates/ui-widgets/src/tile_grid/tile.rs index 712c3c9ce..df1c7959b 100644 --- a/crates/ui-widgets/src/tile_grid/tile.rs +++ b/crates/ui-widgets/src/tile_grid/tile.rs @@ -226,7 +226,9 @@ pub struct TileStyle { /// The glyph of a glyph badge. #[style(icon)] pill_icon: IconLook, + /// 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, dim: StyleColor, /// The ring outside the picture: the accent when selected or current, the muted ink under the pointer. ring: Stateful, @@ -664,6 +666,7 @@ impl Component for Tile<'_> { face: IconLook::new(sizes.face, fixed(text.muted)).on(fixed(colors.surface.sunken)), 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)), ring, ring_width, @@ -814,7 +817,8 @@ impl Component for Tile<'_> { if style.sizes.card { ui.draw().surface(picture, SurfaceKind::Sunken, Corners::All); } else { - ui.draw().fill(&PaintShape::Rect(picture, flat), style.placeholder); + let placeholder = if cx.env.surface() == SurfaceKind::Sunken { style.placeholder_on_sunken } else { style.placeholder }; + ui.draw().fill(&PaintShape::Rect(picture, flat), placeholder); } if let Some(paint) = self.first.take() { let _ = ui.child("picture", picture, RowThumb::new(paint));