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