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