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