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