icon.rs

 1use gpui2::elements::svg;
 2use gpui2::style::StyleHelpers;
 3use gpui2::{Element, IntoElement, ViewContext};
 4
 5use crate::theme;
 6
 7// Icon::Hash
 8// icon(IconAsset::Hash).color(IconColor::Warning)
 9// Icon::new(IconAsset::Hash).color(IconColor::Warning)
10
11#[derive(Default, PartialEq, Copy, Clone)]
12pub enum IconAsset {
13    Ai,
14    ArrowLeft,
15    ArrowRight,
16    #[default]
17    ArrowUpRight,
18    Bolt,
19    Hash,
20    File,
21    Folder,
22    FolderOpen,
23    ChevronDown,
24    ChevronUp,
25    ChevronLeft,
26    ChevronRight,
27}
28
29impl IconAsset {
30    pub fn path(self) -> &'static str {
31        match self {
32            IconAsset::Ai => "icons/ai.svg",
33            IconAsset::ArrowLeft => "icons/arrow_left.svg",
34            IconAsset::ArrowRight => "icons/arrow_right.svg",
35            IconAsset::ArrowUpRight => "icons/arrow_up_right.svg",
36            IconAsset::Bolt => "icons/bolt.svg",
37            IconAsset::Hash => "icons/hash.svg",
38            IconAsset::ChevronDown => "icons/chevron_down.svg",
39            IconAsset::ChevronUp => "icons/chevron_up.svg",
40            IconAsset::ChevronLeft => "icons/chevron_left.svg",
41            IconAsset::ChevronRight => "icons/chevron_right.svg",
42            IconAsset::File => "icons/file_icons/file.svg",
43            IconAsset::Folder => "icons/file_icons/folder.svg",
44            IconAsset::FolderOpen => "icons/file_icons/folder_open.svg",
45        }
46    }
47}
48
49#[derive(Element, Clone)]
50pub struct Icon {
51    asset: IconAsset,
52}
53
54pub fn icon(asset: IconAsset) -> Icon {
55    Icon { asset }
56}
57
58// impl Icon {
59//     pub fn new(asset: IconAsset) -> Icon {
60//         Icon { asset }
61//     }
62// }
63
64impl Icon {
65    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
66        let theme = theme(cx);
67
68        svg()
69            .path(self.asset.path())
70            .size_4()
71            .fill(theme.lowest.base.default.foreground)
72    }
73}