diff --git a/crates/layers/src/ui/panel/row.rs b/crates/layers/src/ui/panel/row.rs index 04b154fe0..332f8fa4e 100644 --- a/crates/layers/src/ui/panel/row.rs +++ b/crates/layers/src/ui/panel/row.rs @@ -165,6 +165,20 @@ fn paint_kind_tile(painter: &ContentPainterCx<'_>, rect: Rect, kind: LayerKind) } } +/// The square in the bottom corner of the thumbnail `rect` that a badge fills. +fn badge_area(rect: Rect) -> Rect { + let badge = rect.width().min(rect.height()) * BADGE_SHARE; + Rect::from_min_size(pos2(rect.right() - badge, rect.bottom() - badge), vec2(badge, badge)) +} + +/// The app's badge on a layer thumbnail: its icon on the scrim. +fn paint_thumb_badge(painter: &ContentPainterCx<'_>, rect: Rect, icon: IconId) { + let area = badge_area(rect); + painter.surface(area, SurfaceKind::Scrim, Corners::None); + let glyph = area.shrink(area.width() * CROSS_INSET_SHARE); + painter.icon(glyph, &IconSpec::svg(icon).ink(SurfaceKind::Scrim.ink())); +} + /// The cross of a disabled mask and the badge that names a layer or vector mask. fn paint_mask_marks(painter: &ContentPainterCx<'_>, rect: Rect, mask: &MaskInfo, badges: bool) { let side = rect.width().min(rect.height()); @@ -175,8 +189,8 @@ fn paint_mask_marks(painter: &ContentPainterCx<'_>, rect: Rect, mask: &MaskInfo, painter.painter.line_segment([inner.right_top(), inner.left_bottom()], stroke); } if badges { - let badge = side * BADGE_SHARE; - let area = Rect::from_min_size(pos2(rect.right() - badge, rect.bottom() - badge), vec2(badge, badge)); + let area = badge_area(rect); + let badge = area.width(); painter.surface(area, SurfaceKind::Scrim, Corners::None); let ink = painter.ink_on(SurfaceKind::Scrim); let glyph = Stroke::new(badge * MARK_WIDTH_SHARE * 2.0, ink); @@ -217,11 +231,14 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR if size != ThumbSize::None && !compact { let host = cx.thumbs; - let (layer, kind) = (id.clone(), info.kind); + let (layer, kind, badge) = (id.clone(), info.kind, info.thumb_badge.clone()); row = row.thumb(size, move |painter, rect| { if !paint_picture(host, &LayerThumb::pixels(layer, contents), painter, rect, &PicturePaint::default()) { paint_kind_tile(painter, rect, kind); } + if let Some(icon) = badge { + paint_thumb_badge(painter, rect, icon); + } }); let frame = info.kind == LayerKind::Frame; if frame { diff --git a/crates/layers/src/ui/tree.rs b/crates/layers/src/ui/tree.rs index 1a807702d..7374bdb85 100644 --- a/crates/layers/src/ui/tree.rs +++ b/crates/layers/src/ui/tree.rs @@ -153,6 +153,9 @@ pub struct LayerInfo { /// Whether Cmd/Ctrl-click on the layer thumbnail loads it as a selection; false for the /// Background, where Cmd-click is a plain click. pub thumb_loads_selection: bool, + /// A badge in the layer thumbnail's corner on the scrim, as the mask badges: PhotoCraft's smart + /// object and shape marks. The app names it in [`description`](Self::description). + pub thumb_badge: Option, /// The app's own words, added to the row's description for a screen reader. pub description: Option, } @@ -183,6 +186,7 @@ impl LayerInfo { smart_filters_enabled: true, warning: None, thumb_loads_selection: true, + thumb_badge: None, description: None, } }