1use std::sync::Arc;
2
3use gpui2::elements::svg;
4use gpui2::Hsla;
5use strum::EnumIter;
6
7use crate::prelude::*;
8use crate::theme::theme;
9use crate::Theme;
10
11#[derive(Default, PartialEq, Copy, Clone)]
12pub enum IconSize {
13 Small,
14 #[default]
15 Large,
16}
17
18#[derive(Default, PartialEq, Copy, Clone)]
19pub enum IconColor {
20 #[default]
21 Default,
22 Muted,
23 Disabled,
24 Placeholder,
25 Accent,
26 Error,
27 Warning,
28 Success,
29 Info,
30}
31
32impl IconColor {
33 pub fn color(self, theme: Arc<Theme>) -> Hsla {
34 match self {
35 IconColor::Default => theme.lowest.base.default.foreground,
36 IconColor::Muted => theme.lowest.variant.default.foreground,
37 IconColor::Disabled => theme.lowest.base.disabled.foreground,
38 IconColor::Placeholder => theme.lowest.base.disabled.foreground,
39 IconColor::Accent => theme.lowest.accent.default.foreground,
40 IconColor::Error => theme.lowest.negative.default.foreground,
41 IconColor::Warning => theme.lowest.warning.default.foreground,
42 IconColor::Success => theme.lowest.positive.default.foreground,
43 IconColor::Info => theme.lowest.accent.default.foreground,
44 }
45 }
46}
47
48#[derive(Default, PartialEq, Copy, Clone, EnumIter)]
49pub enum Icon {
50 Ai,
51 ArrowLeft,
52 ArrowRight,
53 ArrowUpRight,
54 AudioOff,
55 AudioOn,
56 Bolt,
57 ChevronDown,
58 ChevronLeft,
59 ChevronRight,
60 ChevronUp,
61 Close,
62 ExclamationTriangle,
63 ExternalLink,
64 File,
65 FileGeneric,
66 FileDoc,
67 FileGit,
68 FileLock,
69 FileRust,
70 FileToml,
71 FileTree,
72 Folder,
73 FolderOpen,
74 FolderX,
75 #[default]
76 Hash,
77 InlayHint,
78 MagicWand,
79 MagnifyingGlass,
80 Maximize,
81 Menu,
82 MessageBubbles,
83 Mic,
84 MicMute,
85 Plus,
86 Quote,
87 Screen,
88 SelectAll,
89 Split,
90 SplitMessage,
91 Terminal,
92 XCircle,
93 Copilot,
94 Envelope,
95}
96
97impl Icon {
98 pub fn path(self) -> &'static str {
99 match self {
100 Icon::Ai => "icons/ai.svg",
101 Icon::ArrowLeft => "icons/arrow_left.svg",
102 Icon::ArrowRight => "icons/arrow_right.svg",
103 Icon::ArrowUpRight => "icons/arrow_up_right.svg",
104 Icon::AudioOff => "icons/speaker-off.svg",
105 Icon::AudioOn => "icons/speaker-loud.svg",
106 Icon::Bolt => "icons/bolt.svg",
107 Icon::ChevronDown => "icons/chevron_down.svg",
108 Icon::ChevronLeft => "icons/chevron_left.svg",
109 Icon::ChevronRight => "icons/chevron_right.svg",
110 Icon::ChevronUp => "icons/chevron_up.svg",
111 Icon::Close => "icons/x.svg",
112 Icon::ExclamationTriangle => "icons/warning.svg",
113 Icon::ExternalLink => "icons/external_link.svg",
114 Icon::File => "icons/file.svg",
115 Icon::FileGeneric => "icons/file_icons/file.svg",
116 Icon::FileDoc => "icons/file_icons/book.svg",
117 Icon::FileGit => "icons/file_icons/git.svg",
118 Icon::FileLock => "icons/file_icons/lock.svg",
119 Icon::FileRust => "icons/file_icons/rust.svg",
120 Icon::FileToml => "icons/file_icons/toml.svg",
121 Icon::FileTree => "icons/project.svg",
122 Icon::Folder => "icons/file_icons/folder.svg",
123 Icon::FolderOpen => "icons/file_icons/folder_open.svg",
124 Icon::FolderX => "icons/stop_sharing.svg",
125 Icon::Hash => "icons/hash.svg",
126 Icon::InlayHint => "icons/inlay_hint.svg",
127 Icon::MagicWand => "icons/magic-wand.svg",
128 Icon::MagnifyingGlass => "icons/magnifying_glass.svg",
129 Icon::Maximize => "icons/maximize.svg",
130 Icon::Menu => "icons/menu.svg",
131 Icon::MessageBubbles => "icons/conversations.svg",
132 Icon::Mic => "icons/mic.svg",
133 Icon::MicMute => "icons/mic-mute.svg",
134 Icon::Plus => "icons/plus.svg",
135 Icon::Quote => "icons/quote.svg",
136 Icon::Screen => "icons/desktop.svg",
137 Icon::SelectAll => "icons/select-all.svg",
138 Icon::Split => "icons/split.svg",
139 Icon::SplitMessage => "icons/split_message.svg",
140 Icon::Terminal => "icons/terminal.svg",
141 Icon::XCircle => "icons/error.svg",
142 Icon::Copilot => "icons/copilot.svg",
143 Icon::Envelope => "icons/feedback.svg",
144 }
145 }
146}
147
148#[derive(Element, Clone)]
149pub struct IconElement {
150 icon: Icon,
151 color: IconColor,
152 size: IconSize,
153}
154
155impl IconElement {
156 pub fn new(icon: Icon) -> Self {
157 Self {
158 icon,
159 color: IconColor::default(),
160 size: IconSize::default(),
161 }
162 }
163
164 pub fn color(mut self, color: IconColor) -> Self {
165 self.color = color;
166 self
167 }
168
169 pub fn size(mut self, size: IconSize) -> Self {
170 self.size = size;
171 self
172 }
173
174 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
175 let theme = theme(cx);
176 let fill = self.color.color(theme);
177
178 let sized_svg = match self.size {
179 IconSize::Small => svg().size_3p5(),
180 IconSize::Large => svg().size_4(),
181 };
182
183 sized_svg.flex_none().path(self.icon.path()).fill(fill)
184 }
185}