prelude.rs

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