1use gpui::{rems, svg, IntoElement, Rems};
2use strum::EnumIter;
3
4use crate::prelude::*;
5
6#[derive(Default, PartialEq, Copy, Clone)]
7pub enum IconSize {
8 XSmall,
9 Small,
10 #[default]
11 Medium,
12}
13
14impl IconSize {
15 pub fn rems(self) -> Rems {
16 match self {
17 IconSize::XSmall => rems(12. / 16.),
18 IconSize::Small => rems(14. / 16.),
19 IconSize::Medium => rems(16. / 16.),
20 }
21 }
22}
23
24#[derive(Debug, PartialEq, Copy, Clone, EnumIter)]
25pub enum Icon {
26 Ai,
27 ArrowDown,
28 ArrowLeft,
29 ArrowRight,
30 ArrowUp,
31 ArrowUpRight,
32 AtSign,
33 AudioOff,
34 AudioOn,
35 Backspace,
36 Bell,
37 BellOff,
38 BellRing,
39 Bolt,
40 CaseSensitive,
41 Check,
42 ChevronDown,
43 ChevronLeft,
44 ChevronRight,
45 ChevronUp,
46 Close,
47 Collab,
48 Command,
49 Control,
50 Copilot,
51 CopilotDisabled,
52 CopilotError,
53 CopilotInit,
54 Copy,
55 Dash,
56 Delete,
57 Disconnected,
58 Ellipsis,
59 Envelope,
60 Escape,
61 ExclamationTriangle,
62 Exit,
63 ExternalLink,
64 File,
65 FileDoc,
66 FileGeneric,
67 FileGit,
68 FileLock,
69 FileRust,
70 FileToml,
71 FileTree,
72 Filter,
73 Folder,
74 FolderOpen,
75 FolderX,
76 Github,
77 Hash,
78 InlayHint,
79 Link,
80 MagicWand,
81 MagnifyingGlass,
82 MailOpen,
83 Maximize,
84 Menu,
85 MessageBubbles,
86 Mic,
87 MicMute,
88 Minimize,
89 Option,
90 PageDown,
91 PageUp,
92 Plus,
93 Public,
94 Quote,
95 Replace,
96 ReplaceAll,
97 ReplaceNext,
98 Return,
99 Screen,
100 SelectAll,
101 Shift,
102 Snip,
103 Space,
104 Split,
105 Tab,
106 Terminal,
107 Update,
108 WholeWord,
109 XCircle,
110 ZedXCopilot,
111}
112
113impl Icon {
114 pub fn path(self) -> &'static str {
115 match self {
116 Icon::Ai => "icons/ai.svg",
117 Icon::ArrowDown => "icons/arrow_down.svg",
118 Icon::ArrowLeft => "icons/arrow_left.svg",
119 Icon::ArrowRight => "icons/arrow_right.svg",
120 Icon::ArrowUp => "icons/arrow_up.svg",
121 Icon::ArrowUpRight => "icons/arrow_up_right.svg",
122 Icon::AtSign => "icons/at_sign.svg",
123 Icon::AudioOff => "icons/speaker_off.svg",
124 Icon::AudioOn => "icons/speaker-loud.svg",
125 Icon::Backspace => "icons/backspace.svg",
126 Icon::Bell => "icons/bell.svg",
127 Icon::BellOff => "icons/bell_off.svg",
128 Icon::BellRing => "icons/bell_ring.svg",
129 Icon::Bolt => "icons/bolt.svg",
130 Icon::CaseSensitive => "icons/case_insensitive.svg",
131 Icon::Check => "icons/check.svg",
132 Icon::ChevronDown => "icons/chevron_down.svg",
133 Icon::ChevronLeft => "icons/chevron_left.svg",
134 Icon::ChevronRight => "icons/chevron_right.svg",
135 Icon::ChevronUp => "icons/chevron_up.svg",
136 Icon::Close => "icons/x.svg",
137 Icon::Collab => "icons/user_group_16.svg",
138 Icon::Command => "icons/command.svg",
139 Icon::Control => "icons/control.svg",
140 Icon::Copilot => "icons/copilot.svg",
141 Icon::CopilotDisabled => "icons/copilot_disabled.svg",
142 Icon::CopilotError => "icons/copilot_error.svg",
143 Icon::CopilotInit => "icons/copilot_init.svg",
144 Icon::Copy => "icons/copy.svg",
145 Icon::Dash => "icons/dash.svg",
146 Icon::Delete => "icons/delete.svg",
147 Icon::Disconnected => "icons/disconnected.svg",
148 Icon::Ellipsis => "icons/ellipsis.svg",
149 Icon::Envelope => "icons/feedback.svg",
150 Icon::Escape => "icons/escape.svg",
151 Icon::ExclamationTriangle => "icons/warning.svg",
152 Icon::Exit => "icons/exit.svg",
153 Icon::ExternalLink => "icons/external_link.svg",
154 Icon::File => "icons/file.svg",
155 Icon::FileDoc => "icons/file_icons/book.svg",
156 Icon::FileGeneric => "icons/file_icons/file.svg",
157 Icon::FileGit => "icons/file_icons/git.svg",
158 Icon::FileLock => "icons/file_icons/lock.svg",
159 Icon::FileRust => "icons/file_icons/rust.svg",
160 Icon::FileToml => "icons/file_icons/toml.svg",
161 Icon::FileTree => "icons/project.svg",
162 Icon::Filter => "icons/filter.svg",
163 Icon::Folder => "icons/file_icons/folder.svg",
164 Icon::FolderOpen => "icons/file_icons/folder_open.svg",
165 Icon::FolderX => "icons/stop_sharing.svg",
166 Icon::Github => "icons/github.svg",
167 Icon::Hash => "icons/hash.svg",
168 Icon::InlayHint => "icons/inlay_hint.svg",
169 Icon::Link => "icons/link.svg",
170 Icon::MagicWand => "icons/magic_wand.svg",
171 Icon::MagnifyingGlass => "icons/magnifying_glass.svg",
172 Icon::MailOpen => "icons/mail_open.svg",
173 Icon::Maximize => "icons/maximize.svg",
174 Icon::Menu => "icons/menu.svg",
175 Icon::MessageBubbles => "icons/conversations.svg",
176 Icon::Mic => "icons/mic.svg",
177 Icon::MicMute => "icons/mic_mute.svg",
178 Icon::Minimize => "icons/minimize.svg",
179 Icon::Option => "icons/option.svg",
180 Icon::PageDown => "icons/page_down.svg",
181 Icon::PageUp => "icons/page_up.svg",
182 Icon::Plus => "icons/plus.svg",
183 Icon::Public => "icons/public.svg",
184 Icon::Quote => "icons/quote.svg",
185 Icon::Replace => "icons/replace.svg",
186 Icon::ReplaceAll => "icons/replace_all.svg",
187 Icon::ReplaceNext => "icons/replace_next.svg",
188 Icon::Return => "icons/return.svg",
189 Icon::Screen => "icons/desktop.svg",
190 Icon::SelectAll => "icons/select_all.svg",
191 Icon::Shift => "icons/shift.svg",
192 Icon::Snip => "icons/snip.svg",
193 Icon::Space => "icons/space.svg",
194 Icon::Split => "icons/split.svg",
195 Icon::Tab => "icons/tab.svg",
196 Icon::Terminal => "icons/terminal.svg",
197 Icon::Update => "icons/update.svg",
198 Icon::WholeWord => "icons/word_search.svg",
199 Icon::XCircle => "icons/error.svg",
200 Icon::ZedXCopilot => "icons/zed_x_copilot.svg",
201 }
202 }
203}
204
205#[derive(IntoElement)]
206pub struct IconElement {
207 path: SharedString,
208 color: Color,
209 size: IconSize,
210}
211
212impl RenderOnce for IconElement {
213 fn render(self, cx: &mut WindowContext) -> impl IntoElement {
214 svg()
215 .size(self.size.rems())
216 .flex_none()
217 .path(self.path)
218 .text_color(self.color.color(cx))
219 }
220}
221
222impl IconElement {
223 pub fn new(icon: Icon) -> Self {
224 Self {
225 path: icon.path().into(),
226 color: Color::default(),
227 size: IconSize::default(),
228 }
229 }
230
231 pub fn from_path(path: impl Into<SharedString>) -> Self {
232 Self {
233 path: path.into(),
234 color: Color::default(),
235 size: IconSize::default(),
236 }
237 }
238
239 pub fn color(mut self, color: Color) -> Self {
240 self.color = color;
241 self
242 }
243
244 pub fn size(mut self, size: IconSize) -> Self {
245 self.size = size;
246 self
247 }
248}