1pub use gpui2::elements::div::{div, ScrollState};
2pub use gpui2::style::{StyleHelpers, Styleable};
3pub use gpui2::{Element, IntoElement, ParentElement, ViewContext};
4
5pub use crate::{theme, ButtonVariant, HackyChildren, HackyChildrenPayload, InputVariant, Theme};
6
7use gpui2::{hsla, rgb, Hsla, WindowContext};
8use strum::EnumIter;
9
10#[derive(Default)]
11pub struct SystemColor {
12 pub transparent: Hsla,
13 pub mac_os_traffic_light_red: Hsla,
14 pub mac_os_traffic_light_yellow: Hsla,
15 pub mac_os_traffic_light_green: Hsla,
16}
17
18impl SystemColor {
19 pub fn new() -> SystemColor {
20 SystemColor {
21 transparent: hsla(0.0, 0.0, 0.0, 0.0),
22 mac_os_traffic_light_red: rgb::<Hsla>(0xEC695E),
23 mac_os_traffic_light_yellow: rgb::<Hsla>(0xF4BF4F),
24 mac_os_traffic_light_green: rgb::<Hsla>(0x62C554),
25 }
26 }
27 pub fn color(&self) -> Hsla {
28 self.transparent
29 }
30}
31
32#[derive(Clone, Copy)]
33pub struct ThemeColor {
34 pub border: Hsla,
35 pub border_variant: Hsla,
36 /// The background color of an elevated surface, like a modal, tooltip or toast.
37 pub elevated_surface: Hsla,
38}
39
40impl ThemeColor {
41 pub fn new(cx: &WindowContext) -> Self {
42 let theme = theme(cx);
43
44 Self {
45 border: theme.lowest.base.default.border,
46 border_variant: theme.lowest.variant.default.border,
47 elevated_surface: theme.middle.base.default.background,
48 }
49 }
50}
51
52#[derive(Default, PartialEq, EnumIter, Clone, Copy)]
53pub enum HighlightColor {
54 #[default]
55 Default,
56 Comment,
57 String,
58 Function,
59 Keyword,
60}
61
62impl HighlightColor {
63 pub fn hsla(&self, theme: &Theme) -> Hsla {
64 let system_color = SystemColor::new();
65
66 match self {
67 Self::Default => theme
68 .syntax
69 .get("primary")
70 .expect("no theme.syntax.primary")
71 .clone(),
72 Self::Comment => theme
73 .syntax
74 .get("comment")
75 .expect("no theme.syntax.comment")
76 .clone(),
77 Self::String => theme
78 .syntax
79 .get("string")
80 .expect("no theme.syntax.string")
81 .clone(),
82 Self::Function => theme
83 .syntax
84 .get("function")
85 .expect("no theme.syntax.function")
86 .clone(),
87 Self::Keyword => theme
88 .syntax
89 .get("keyword")
90 .expect("no theme.syntax.keyword")
91 .clone(),
92 }
93 }
94}
95
96#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
97pub enum FileSystemStatus {
98 #[default]
99 None,
100 Conflict,
101 Deleted,
102}
103
104impl FileSystemStatus {
105 pub fn to_string(&self) -> String {
106 match self {
107 Self::None => "None".to_string(),
108 Self::Conflict => "Conflict".to_string(),
109 Self::Deleted => "Deleted".to_string(),
110 }
111 }
112}
113
114#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
115pub enum GitStatus {
116 #[default]
117 None,
118 Created,
119 Modified,
120 Deleted,
121 Conflict,
122 Renamed,
123}
124
125impl GitStatus {
126 pub fn to_string(&self) -> String {
127 match self {
128 Self::None => "None".to_string(),
129 Self::Created => "Created".to_string(),
130 Self::Modified => "Modified".to_string(),
131 Self::Deleted => "Deleted".to_string(),
132 Self::Conflict => "Conflict".to_string(),
133 Self::Renamed => "Renamed".to_string(),
134 }
135 }
136
137 pub fn hsla(&self, cx: &WindowContext) -> Hsla {
138 let theme = theme(cx);
139 let system_color = SystemColor::new();
140
141 match self {
142 Self::None => system_color.transparent,
143 Self::Created => theme.lowest.positive.default.foreground,
144 Self::Modified => theme.lowest.warning.default.foreground,
145 Self::Deleted => theme.lowest.negative.default.foreground,
146 Self::Conflict => theme.lowest.warning.default.foreground,
147 Self::Renamed => theme.lowest.accent.default.foreground,
148 }
149 }
150}
151
152#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
153pub enum DiagnosticStatus {
154 #[default]
155 None,
156 Error,
157 Warning,
158 Info,
159}
160
161#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
162pub enum IconSide {
163 #[default]
164 Left,
165 Right,
166}
167
168#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
169pub enum OrderMethod {
170 #[default]
171 Ascending,
172 Descending,
173 MostRecent,
174}
175
176#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
177pub enum Shape {
178 #[default]
179 Circle,
180 RoundedRectangle,
181}
182
183#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
184pub enum DisclosureControlVisibility {
185 #[default]
186 OnHover,
187 Always,
188}
189
190#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
191pub enum InteractionState {
192 #[default]
193 Enabled,
194 Hovered,
195 Active,
196 Focused,
197 Disabled,
198}
199
200impl InteractionState {
201 pub fn if_enabled(&self, enabled: bool) -> Self {
202 if enabled {
203 *self
204 } else {
205 InteractionState::Disabled
206 }
207 }
208}
209
210#[derive(Default, PartialEq)]
211pub enum SelectedState {
212 #[default]
213 Unselected,
214 PartiallySelected,
215 Selected,
216}
217
218#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
219pub enum Toggleable {
220 Toggleable(ToggleState),
221 #[default]
222 NotToggleable,
223}
224
225impl Toggleable {
226 pub fn is_toggled(&self) -> bool {
227 match self {
228 Self::Toggleable(ToggleState::Toggled) => true,
229 _ => false,
230 }
231 }
232}
233
234impl From<ToggleState> for Toggleable {
235 fn from(state: ToggleState) -> Self {
236 Self::Toggleable(state)
237 }
238}
239
240#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
241pub enum ToggleState {
242 /// The "on" state of a toggleable element.
243 ///
244 /// Example:
245 /// - A collasable list that is currently expanded
246 /// - A toggle button that is currently on.
247 Toggled,
248 /// The "off" state of a toggleable element.
249 ///
250 /// Example:
251 /// - A collasable list that is currently collapsed
252 /// - A toggle button that is currently off.
253 #[default]
254 NotToggled,
255}
256
257impl From<Toggleable> for ToggleState {
258 fn from(toggleable: Toggleable) -> Self {
259 match toggleable {
260 Toggleable::Toggleable(state) => state,
261 Toggleable::NotToggleable => ToggleState::NotToggled,
262 }
263 }
264}
265
266impl From<bool> for ToggleState {
267 fn from(toggled: bool) -> Self {
268 if toggled {
269 ToggleState::Toggled
270 } else {
271 ToggleState::NotToggled
272 }
273 }
274}