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