1pub use gpui2::{
2 div, Component, Element, ElementId, ParentElement, SharedString, StatefulInteractive,
3 StatelessInteractive, Styled, ViewContext, WindowContext,
4};
5
6pub use crate::elevation::*;
7use crate::settings::user_settings;
8pub use crate::ButtonVariant;
9pub use theme2::theme;
10
11use gpui2::{rems, Hsla, Rems};
12use strum::EnumIter;
13
14pub fn ui_size(cx: &mut WindowContext, size: f32) -> Rems {
15 const UI_SCALE_RATIO: f32 = 0.875;
16
17 let settings = user_settings(cx);
18
19 rems(*settings.ui_scale * UI_SCALE_RATIO * size)
20}
21
22#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
23pub enum FileSystemStatus {
24 #[default]
25 None,
26 Conflict,
27 Deleted,
28}
29
30impl std::fmt::Display for FileSystemStatus {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 write!(
33 f,
34 "{}",
35 match self {
36 Self::None => "None",
37 Self::Conflict => "Conflict",
38 Self::Deleted => "Deleted",
39 }
40 )
41 }
42}
43
44#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
45pub enum GitStatus {
46 #[default]
47 None,
48 Created,
49 Modified,
50 Deleted,
51 Conflict,
52 Renamed,
53}
54
55impl GitStatus {
56 pub fn hsla(&self, cx: &WindowContext) -> Hsla {
57 let theme = theme(cx);
58
59 match self {
60 Self::None => theme.transparent,
61 Self::Created => theme.git_created,
62 Self::Modified => theme.git_modified,
63 Self::Deleted => theme.git_deleted,
64 Self::Conflict => theme.git_conflict,
65 Self::Renamed => theme.git_renamed,
66 }
67 }
68}
69
70impl std::fmt::Display for GitStatus {
71 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72 write!(
73 f,
74 "{}",
75 match self {
76 Self::None => "None",
77 Self::Created => "Created",
78 Self::Modified => "Modified",
79 Self::Deleted => "Deleted",
80 Self::Conflict => "Conflict",
81 Self::Renamed => "Renamed",
82 }
83 )
84 }
85}
86
87#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
88pub enum DiagnosticStatus {
89 #[default]
90 None,
91 Error,
92 Warning,
93 Info,
94}
95
96#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
97pub enum IconSide {
98 #[default]
99 Left,
100 Right,
101}
102
103#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
104pub enum OrderMethod {
105 #[default]
106 Ascending,
107 Descending,
108 MostRecent,
109}
110
111#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
112pub enum Shape {
113 #[default]
114 Circle,
115 RoundedRectangle,
116}
117
118#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
119pub enum DisclosureControlVisibility {
120 #[default]
121 OnHover,
122 Always,
123}
124
125#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
126pub enum DisclosureControlStyle {
127 /// Shows the disclosure control only when hovered where possible.
128 ///
129 /// More compact, but not available everywhere.
130 ChevronOnHover,
131 /// Shows an icon where possible, otherwise shows a chevron.
132 ///
133 /// For example, in a file tree a folder or file icon is shown
134 /// instead of a chevron
135 Icon,
136 /// Always shows a chevron.
137 Chevron,
138 /// Completely hides the disclosure control where possible.
139 None,
140}
141
142#[derive(Debug, PartialEq, Eq, Clone, Copy, EnumIter)]
143pub enum OverflowStyle {
144 Hidden,
145 Wrap,
146}
147
148#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
149pub enum InteractionState {
150 #[default]
151 Enabled,
152 Hovered,
153 Active,
154 Focused,
155 Disabled,
156}
157
158impl InteractionState {
159 pub fn if_enabled(&self, enabled: bool) -> Self {
160 if enabled {
161 *self
162 } else {
163 InteractionState::Disabled
164 }
165 }
166}
167
168#[derive(Default, PartialEq)]
169pub enum SelectedState {
170 #[default]
171 Unselected,
172 PartiallySelected,
173 Selected,
174}
175
176#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
177pub enum Toggleable {
178 Toggleable(ToggleState),
179 #[default]
180 NotToggleable,
181}
182
183impl Toggleable {
184 pub fn is_toggled(&self) -> bool {
185 match self {
186 Self::Toggleable(ToggleState::Toggled) => true,
187 _ => false,
188 }
189 }
190}
191
192impl From<ToggleState> for Toggleable {
193 fn from(state: ToggleState) -> Self {
194 Self::Toggleable(state)
195 }
196}
197
198#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
199pub enum ToggleState {
200 /// The "on" state of a toggleable element.
201 ///
202 /// Example:
203 /// - A collasable list that is currently expanded
204 /// - A toggle button that is currently on.
205 Toggled,
206 /// The "off" state of a toggleable element.
207 ///
208 /// Example:
209 /// - A collasable list that is currently collapsed
210 /// - A toggle button that is currently off.
211 #[default]
212 NotToggled,
213}
214
215impl From<Toggleable> for ToggleState {
216 fn from(toggleable: Toggleable) -> Self {
217 match toggleable {
218 Toggleable::Toggleable(state) => state,
219 Toggleable::NotToggleable => ToggleState::NotToggled,
220 }
221 }
222}
223
224impl From<bool> for ToggleState {
225 fn from(toggled: bool) -> Self {
226 if toggled {
227 ToggleState::Toggled
228 } else {
229 ToggleState::NotToggled
230 }
231 }
232}