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};
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(Default, PartialEq, EnumIter, Clone, Copy)]
33pub enum HighlightColor {
34 #[default]
35 Default,
36 Comment,
37 String,
38 Function,
39 Keyword,
40}
41
42impl HighlightColor {
43 pub fn hsla(&self, cx: &WindowContext) -> Hsla {
44 let theme = theme(cx);
45 let system_color = SystemColor::new();
46
47 match self {
48 Self::Default => theme
49 .syntax
50 .get("primary")
51 .expect("no theme.syntax.primary")
52 .clone(),
53 Self::Comment => theme
54 .syntax
55 .get("comment")
56 .expect("no theme.syntax.comment")
57 .clone(),
58 Self::String => theme
59 .syntax
60 .get("string")
61 .expect("no theme.syntax.string")
62 .clone(),
63 Self::Function => theme
64 .syntax
65 .get("function")
66 .expect("no theme.syntax.function")
67 .clone(),
68 Self::Keyword => theme
69 .syntax
70 .get("keyword")
71 .expect("no theme.syntax.keyword")
72 .clone(),
73 }
74 }
75}
76
77#[derive(Default, PartialEq, EnumIter)]
78pub enum FileSystemStatus {
79 #[default]
80 None,
81 Conflict,
82 Deleted,
83}
84
85impl FileSystemStatus {
86 pub fn to_string(&self) -> String {
87 match self {
88 Self::None => "None".to_string(),
89 Self::Conflict => "Conflict".to_string(),
90 Self::Deleted => "Deleted".to_string(),
91 }
92 }
93}
94
95#[derive(Default, PartialEq, EnumIter, Clone, Copy)]
96pub enum GitStatus {
97 #[default]
98 None,
99 Created,
100 Modified,
101 Deleted,
102 Conflict,
103 Renamed,
104}
105
106impl GitStatus {
107 pub fn to_string(&self) -> String {
108 match self {
109 Self::None => "None".to_string(),
110 Self::Created => "Created".to_string(),
111 Self::Modified => "Modified".to_string(),
112 Self::Deleted => "Deleted".to_string(),
113 Self::Conflict => "Conflict".to_string(),
114 Self::Renamed => "Renamed".to_string(),
115 }
116 }
117
118 pub fn hsla(&self, cx: &WindowContext) -> Hsla {
119 let theme = theme(cx);
120 let system_color = SystemColor::new();
121
122 match self {
123 Self::None => system_color.transparent,
124 Self::Created => theme.lowest.positive.default.foreground,
125 Self::Modified => theme.lowest.warning.default.foreground,
126 Self::Deleted => theme.lowest.negative.default.foreground,
127 Self::Conflict => theme.lowest.warning.default.foreground,
128 Self::Renamed => theme.lowest.accent.default.foreground,
129 }
130 }
131}
132
133#[derive(Default, PartialEq)]
134pub enum DiagnosticStatus {
135 #[default]
136 None,
137 Error,
138 Warning,
139 Info,
140}
141
142#[derive(Default, PartialEq)]
143pub enum IconSide {
144 #[default]
145 Left,
146 Right,
147}
148
149#[derive(Default, PartialEq)]
150pub enum OrderMethod {
151 #[default]
152 Ascending,
153 Descending,
154 MostRecent,
155}
156
157#[derive(Default, PartialEq, Clone, Copy)]
158pub enum Shape {
159 #[default]
160 Circle,
161 RoundedRectangle,
162}
163
164#[derive(Default, PartialEq, Clone, Copy)]
165pub enum DisclosureControlVisibility {
166 #[default]
167 OnHover,
168 Always,
169}
170
171#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
172pub enum InteractionState {
173 #[default]
174 Enabled,
175 Hovered,
176 Active,
177 Focused,
178 Disabled,
179}
180
181impl InteractionState {
182 pub fn if_enabled(&self, enabled: bool) -> Self {
183 if enabled {
184 *self
185 } else {
186 InteractionState::Disabled
187 }
188 }
189}
190
191#[derive(Default, PartialEq)]
192pub enum SelectedState {
193 #[default]
194 Unselected,
195 PartiallySelected,
196 Selected,
197}
198
199#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
200pub enum Toggleable {
201 Toggleable(ToggleState),
202 #[default]
203 NotToggleable,
204}
205
206impl Toggleable {
207 pub fn is_toggled(&self) -> bool {
208 match self {
209 Self::Toggleable(ToggleState::Toggled) => true,
210 _ => false,
211 }
212 }
213}
214
215impl From<ToggleState> for Toggleable {
216 fn from(state: ToggleState) -> Self {
217 Self::Toggleable(state)
218 }
219}
220
221#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
222pub enum ToggleState {
223 /// The "on" state of a toggleable element.
224 ///
225 /// Example:
226 /// - A collasable list that is currently expanded
227 /// - A toggle button that is currently on.
228 Toggled,
229 /// The "off" state of a toggleable element.
230 ///
231 /// Example:
232 /// - A collasable list that is currently collapsed
233 /// - A toggle button that is currently off.
234 #[default]
235 NotToggled,
236}
237
238impl From<Toggleable> for ToggleState {
239 fn from(toggleable: Toggleable) -> Self {
240 match toggleable {
241 Toggleable::Toggleable(state) => state,
242 Toggleable::NotToggleable => ToggleState::NotToggled,
243 }
244 }
245}
246
247impl From<bool> for ToggleState {
248 fn from(toggled: bool) -> Self {
249 if toggled {
250 ToggleState::Toggled
251 } else {
252 ToggleState::NotToggled
253 }
254 }
255}