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