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