Skip to main content

ui/widgets/
icon.rs

1//! Icons, as the environment paints them.
2//!
3//! A catalog trait, like every widget group: import it to unlock
4//! `theme.icon(..)` and `theme.icon_at(..)`.
5
6use gpui::{Svg, prelude::*, px};
7use icons::Icon;
8use theme::{TextStyle, ThemeExt};
9
10pub trait Icons: ThemeExt {
11    /// An icon at the ladder's body step, in the plain text tone.
12    ///
13    /// Both are defaults, not decisions: `Svg` is `Styled`, so a later
14    /// `.size(..)` or `.text_color(..)` wins, and a component's own metric
15    /// stays with the component. What this buys is the floor —
16    /// [`icons::icon`] paints *nothing* when no colour is set anywhere,
17    /// because gpui resolves an svg's tone from its own style and never
18    /// inherits one, so an icon with a forgotten `text_color` is invisible
19    /// rather than wrong.
20    fn icon(&self, icon: impl Into<Icon>) -> Svg {
21        self.icon_at(TextStyle::Body, icon)
22    }
23
24    /// The same, sized to a named rung — a caption's icon beside caption text.
25    /// The ladder is the one type reads, so the two move together when
26    /// [`theme::set_base_text_size`] does.
27    fn icon_at(&self, role: TextStyle, icon: impl Into<Icon>) -> Svg {
28        icons::icon(icon)
29            .size(px(role.painted()))
30            .text_color(self.theme().text)
31    }
32}
33
34impl Icons for theme::Theme {}