prelude.rs

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