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