prelude.rs

  1use gpui::rems;
  2use gpui::Rems;
  3pub use gpui::{
  4    div, Component, Element, ElementId, ParentElement, SharedString, StatefulInteractive,
  5    StatelessInteractive, Styled, ViewContext, WindowContext,
  6};
  7
  8pub use crate::elevation::*;
  9pub use crate::ButtonVariant;
 10pub use theme2::ActiveTheme;
 11
 12use gpui::Hsla;
 13use strum::EnumIter;
 14
 15#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 16pub enum FileSystemStatus {
 17    #[default]
 18    None,
 19    Conflict,
 20    Deleted,
 21}
 22
 23impl std::fmt::Display for FileSystemStatus {
 24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 25        write!(
 26            f,
 27            "{}",
 28            match self {
 29                Self::None => "None",
 30                Self::Conflict => "Conflict",
 31                Self::Deleted => "Deleted",
 32            }
 33        )
 34    }
 35}
 36
 37#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 38pub enum GitStatus {
 39    #[default]
 40    None,
 41    Created,
 42    Modified,
 43    Deleted,
 44    Conflict,
 45    Renamed,
 46}
 47
 48impl GitStatus {
 49    pub fn hsla(&self, cx: &WindowContext) -> Hsla {
 50        match self {
 51            Self::None => cx.theme().system().transparent,
 52            Self::Created => cx.theme().status().created,
 53            Self::Modified => cx.theme().status().modified,
 54            Self::Deleted => cx.theme().status().deleted,
 55            Self::Conflict => cx.theme().status().conflict,
 56            Self::Renamed => cx.theme().status().renamed,
 57        }
 58    }
 59}
 60
 61impl std::fmt::Display for GitStatus {
 62    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 63        write!(
 64            f,
 65            "{}",
 66            match self {
 67                Self::None => "None",
 68                Self::Created => "Created",
 69                Self::Modified => "Modified",
 70                Self::Deleted => "Deleted",
 71                Self::Conflict => "Conflict",
 72                Self::Renamed => "Renamed",
 73            }
 74        )
 75    }
 76}
 77
 78/// The default text size for UI text
 79///
 80/// At a default 16px per rem, this is 14px.
 81///
 82/// Use [`ui_text_sm`] for smaller text.
 83pub fn ui_text_default() -> Rems {
 84    rems(0.875)
 85}
 86
 87/// The small text size for UI text
 88///
 89/// At a default 16px per rem, this is 12px.
 90///
 91/// Use [`ui_text_default`] for regular-sized text.
 92pub fn ui_text_sm() -> Rems {
 93    rems(0.75)
 94}
 95
 96#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 97pub enum DiagnosticStatus {
 98    #[default]
 99    None,
100    Error,
101    Warning,
102    Info,
103}
104
105#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
106pub enum IconSide {
107    #[default]
108    Left,
109    Right,
110}
111
112#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
113pub enum OrderMethod {
114    #[default]
115    Ascending,
116    Descending,
117    MostRecent,
118}
119
120#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
121pub enum Shape {
122    #[default]
123    Circle,
124    RoundedRectangle,
125}
126
127#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
128pub enum DisclosureControlVisibility {
129    #[default]
130    OnHover,
131    Always,
132}
133
134#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
135pub enum DisclosureControlStyle {
136    /// Shows the disclosure control only when hovered where possible.
137    ///
138    /// More compact, but not available everywhere.
139    ChevronOnHover,
140    /// Shows an icon where possible, otherwise shows a chevron.
141    ///
142    /// For example, in a file tree a folder or file icon is shown
143    /// instead of a chevron
144    Icon,
145    /// Always shows a chevron.
146    Chevron,
147    /// Completely hides the disclosure control where possible.
148    None,
149}
150
151#[derive(Debug, PartialEq, Eq, Clone, Copy, EnumIter)]
152pub enum OverflowStyle {
153    Hidden,
154    Wrap,
155}
156
157#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
158pub enum InteractionState {
159    #[default]
160    Enabled,
161    Hovered,
162    Active,
163    Focused,
164    Disabled,
165}
166
167impl InteractionState {
168    pub fn if_enabled(&self, enabled: bool) -> Self {
169        if enabled {
170            *self
171        } else {
172            InteractionState::Disabled
173        }
174    }
175}
176
177#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
178pub enum Selection {
179    #[default]
180    Unselected,
181    Indeterminate,
182    Selected,
183}
184
185impl Selection {
186    pub fn inverse(&self) -> Self {
187        match self {
188            Self::Unselected | Self::Indeterminate => Self::Selected,
189            Self::Selected => Self::Unselected,
190        }
191    }
192}