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::ActiveTheme;
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 match self {
58 Self::None => cx.theme().styles.system.transparent,
59 Self::Created => cx.theme().styles.git.created,
60 Self::Modified => cx.theme().styles.git.modified,
61 Self::Deleted => cx.theme().styles.git.deleted,
62 Self::Conflict => cx.theme().styles.git.conflict,
63 Self::Renamed => cx.theme().styles.git.renamed,
64 }
65 }
66}
67
68impl std::fmt::Display for GitStatus {
69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70 write!(
71 f,
72 "{}",
73 match self {
74 Self::None => "None",
75 Self::Created => "Created",
76 Self::Modified => "Modified",
77 Self::Deleted => "Deleted",
78 Self::Conflict => "Conflict",
79 Self::Renamed => "Renamed",
80 }
81 )
82 }
83}
84
85#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
86pub enum DiagnosticStatus {
87 #[default]
88 None,
89 Error,
90 Warning,
91 Info,
92}
93
94#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
95pub enum IconSide {
96 #[default]
97 Left,
98 Right,
99}
100
101#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
102pub enum OrderMethod {
103 #[default]
104 Ascending,
105 Descending,
106 MostRecent,
107}
108
109#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
110pub enum Shape {
111 #[default]
112 Circle,
113 RoundedRectangle,
114}
115
116#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
117pub enum DisclosureControlVisibility {
118 #[default]
119 OnHover,
120 Always,
121}
122
123#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
124pub enum DisclosureControlStyle {
125 /// Shows the disclosure control only when hovered where possible.
126 ///
127 /// More compact, but not available everywhere.
128 ChevronOnHover,
129 /// Shows an icon where possible, otherwise shows a chevron.
130 ///
131 /// For example, in a file tree a folder or file icon is shown
132 /// instead of a chevron
133 Icon,
134 /// Always shows a chevron.
135 Chevron,
136 /// Completely hides the disclosure control where possible.
137 None,
138}
139
140#[derive(Debug, PartialEq, Eq, Clone, Copy, EnumIter)]
141pub enum OverflowStyle {
142 Hidden,
143 Wrap,
144}
145
146#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
147pub enum InteractionState {
148 #[default]
149 Enabled,
150 Hovered,
151 Active,
152 Focused,
153 Disabled,
154}
155
156impl InteractionState {
157 pub fn if_enabled(&self, enabled: bool) -> Self {
158 if enabled {
159 *self
160 } else {
161 InteractionState::Disabled
162 }
163 }
164}
165
166#[derive(Default, PartialEq)]
167pub enum SelectedState {
168 #[default]
169 Unselected,
170 PartiallySelected,
171 Selected,
172}
173
174#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
175pub enum Toggleable {
176 Toggleable(ToggleState),
177 #[default]
178 NotToggleable,
179}
180
181impl Toggleable {
182 pub fn is_toggled(&self) -> bool {
183 match self {
184 Self::Toggleable(ToggleState::Toggled) => true,
185 _ => false,
186 }
187 }
188}
189
190impl From<ToggleState> for Toggleable {
191 fn from(state: ToggleState) -> Self {
192 Self::Toggleable(state)
193 }
194}
195
196#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
197pub enum ToggleState {
198 /// The "on" state of a toggleable element.
199 ///
200 /// Example:
201 /// - A collasable list that is currently expanded
202 /// - A toggle button that is currently on.
203 Toggled,
204 /// The "off" state of a toggleable element.
205 ///
206 /// Example:
207 /// - A collasable list that is currently collapsed
208 /// - A toggle button that is currently off.
209 #[default]
210 NotToggled,
211}
212
213impl From<Toggleable> for ToggleState {
214 fn from(toggleable: Toggleable) -> Self {
215 match toggleable {
216 Toggleable::Toggleable(state) => state,
217 Toggleable::NotToggleable => ToggleState::NotToggled,
218 }
219 }
220}
221
222impl From<bool> for ToggleState {
223 fn from(toggled: bool) -> Self {
224 if toggled {
225 ToggleState::Toggled
226 } else {
227 ToggleState::NotToggled
228 }
229 }
230}