1use std::sync::Arc;
2
3use gpui2::elements::svg;
4use gpui2::Hsla;
5use strum::EnumIter;
6
7use crate::prelude::*;
8use crate::theme::theme;
9use crate::Theme;
10
11#[derive(Default, PartialEq, Copy, Clone)]
12pub enum IconSize {
13 Small,
14 #[default]
15 Large,
16}
17
18#[derive(Default, PartialEq, Copy, Clone)]
19pub enum IconColor {
20 #[default]
21 Default,
22 Muted,
23 Disabled,
24 Placeholder,
25 Accent,
26 Error,
27 Warning,
28 Success,
29 Info,
30}
31
32impl IconColor {
33 pub fn color(self, theme: Arc<Theme>) -> Hsla {
34 match self {
35 IconColor::Default => theme.lowest.base.default.foreground,
36 IconColor::Muted => theme.lowest.variant.default.foreground,
37 IconColor::Disabled => theme.lowest.base.disabled.foreground,
38 IconColor::Placeholder => theme.lowest.base.disabled.foreground,
39 IconColor::Accent => theme.lowest.accent.default.foreground,
40 IconColor::Error => theme.lowest.negative.default.foreground,
41 IconColor::Warning => theme.lowest.warning.default.foreground,
42 IconColor::Success => theme.lowest.positive.default.foreground,
43 IconColor::Info => theme.lowest.accent.default.foreground,
44 }
45 }
46}
47
48#[derive(Default, PartialEq, Copy, Clone, EnumIter)]
49pub enum Icon {
50 Ai,
51 ArrowLeft,
52 ArrowRight,
53 ArrowUpRight,
54 AudioOff,
55 AudioOn,
56 Bolt,
57 ChevronDown,
58 ChevronLeft,
59 ChevronRight,
60 ChevronUp,
61 Close,
62 ExclamationTriangle,
63 File,
64 FileGeneric,
65 FileDoc,
66 FileGit,
67 FileLock,
68 FileRust,
69 FileToml,
70 FileTree,
71 Folder,
72 FolderOpen,
73 FolderX,
74 #[default]
75 Hash,
76 InlayHint,
77 MagicWand,
78 MagnifyingGlass,
79 Maximize,
80 Menu,
81 MessageBubbles,
82 Mic,
83 MicMute,
84 Plus,
85 Quote,
86 Screen,
87 Split,
88 SplitMessage,
89 Terminal,
90 XCircle,
91 Copilot,
92 Envelope,
93}
94
95impl Icon {
96 pub fn path(self) -> &'static str {
97 match self {
98 Icon::Ai => "icons/ai.svg",
99 Icon::ArrowLeft => "icons/arrow_left.svg",
100 Icon::ArrowRight => "icons/arrow_right.svg",
101 Icon::ArrowUpRight => "icons/arrow_up_right.svg",
102 Icon::AudioOff => "icons/speaker-off.svg",
103 Icon::AudioOn => "icons/speaker-loud.svg",
104 Icon::Bolt => "icons/bolt.svg",
105 Icon::ChevronDown => "icons/chevron_down.svg",
106 Icon::ChevronLeft => "icons/chevron_left.svg",
107 Icon::ChevronRight => "icons/chevron_right.svg",
108 Icon::ChevronUp => "icons/chevron_up.svg",
109 Icon::Close => "icons/x.svg",
110 Icon::ExclamationTriangle => "icons/warning.svg",
111 Icon::File => "icons/file.svg",
112 Icon::FileGeneric => "icons/file_icons/file.svg",
113 Icon::FileDoc => "icons/file_icons/book.svg",
114 Icon::FileGit => "icons/file_icons/git.svg",
115 Icon::FileLock => "icons/file_icons/lock.svg",
116 Icon::FileRust => "icons/file_icons/rust.svg",
117 Icon::FileToml => "icons/file_icons/toml.svg",
118 Icon::FileTree => "icons/project.svg",
119 Icon::Folder => "icons/file_icons/folder.svg",
120 Icon::FolderOpen => "icons/file_icons/folder_open.svg",
121 Icon::FolderX => "icons/stop_sharing.svg",
122 Icon::Hash => "icons/hash.svg",
123 Icon::InlayHint => "icons/inlay_hint.svg",
124 Icon::MagicWand => "icons/magic-wand.svg",
125 Icon::MagnifyingGlass => "icons/magnifying_glass.svg",
126 Icon::Maximize => "icons/maximize.svg",
127 Icon::Menu => "icons/menu.svg",
128 Icon::MessageBubbles => "icons/conversations.svg",
129 Icon::Mic => "icons/mic.svg",
130 Icon::MicMute => "icons/mic-mute.svg",
131 Icon::Plus => "icons/plus.svg",
132 Icon::Quote => "icons/quote.svg",
133 Icon::Screen => "icons/desktop.svg",
134 Icon::Split => "icons/split.svg",
135 Icon::SplitMessage => "icons/split_message.svg",
136 Icon::Terminal => "icons/terminal.svg",
137 Icon::XCircle => "icons/error.svg",
138 Icon::Copilot => "icons/copilot.svg",
139 Icon::Envelope => "icons/feedback.svg",
140 }
141 }
142}
143
144#[derive(Element, Clone)]
145pub struct IconElement {
146 icon: Icon,
147 color: IconColor,
148 size: IconSize,
149}
150
151impl IconElement {
152 pub fn new(icon: Icon) -> Self {
153 Self {
154 icon,
155 color: IconColor::default(),
156 size: IconSize::default(),
157 }
158 }
159
160 pub fn color(mut self, color: IconColor) -> Self {
161 self.color = color;
162 self
163 }
164
165 pub fn size(mut self, size: IconSize) -> Self {
166 self.size = size;
167 self
168 }
169
170 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
171 let theme = theme(cx);
172 let fill = self.color.color(theme);
173
174 let sized_svg = match self.size {
175 IconSize::Small => svg().size_3p5(),
176 IconSize::Large => svg().size_4(),
177 };
178
179 sized_svg.flex_none().path(self.icon.path()).fill(fill)
180 }
181}