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