Skip to main content

gpui_kit_assets/
icon.rs

1use gpui::{AnyElement, App, IntoElement, RenderOnce, SharedString, Styled, Window, svg};
2
3include!(concat!(env!("OUT_DIR"), "/icon_name.rs"));
4
5/// A named icon that resolves to a path in an application's asset source.
6/// Implement this for custom icon sets accepted by GPUI Component's `Icon`.
7pub trait IconNamed {
8    fn path(self) -> SharedString;
9}
10
11impl IconNamed for IconName {
12    fn path(self) -> SharedString {
13        IconName::path(self)
14    }
15}
16
17// Keep direct `.child(IconName::Search)` usable by every presentation layer.
18// Explicit themed sizes and transformations belong to the consumer's Icon.
19impl RenderOnce for IconName {
20    fn render(self, window: &mut Window, _: &mut App) -> impl IntoElement {
21        let text_style = window.text_style();
22        svg()
23            .path(self.path())
24            .flex_shrink_0()
25            .size(text_style.font_size.to_pixels(window.rem_size()))
26            .text_color(text_style.color)
27    }
28}
29
30impl From<IconName> for AnyElement {
31    fn from(name: IconName) -> Self {
32        name.into_any_element()
33    }
34}