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