prelude.rs

  1pub use gpui2::{
  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 gpui2::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(Default, PartialEq)]
158pub enum SelectedState {
159    #[default]
160    Unselected,
161    PartiallySelected,
162    Selected,
163}
164
165#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
166pub enum Toggleable {
167    Toggleable(ToggleState),
168    #[default]
169    NotToggleable,
170}
171
172impl Toggleable {
173    pub fn is_toggled(&self) -> bool {
174        match self {
175            Self::Toggleable(ToggleState::Toggled) => true,
176            _ => false,
177        }
178    }
179}
180
181impl From<ToggleState> for Toggleable {
182    fn from(state: ToggleState) -> Self {
183        Self::Toggleable(state)
184    }
185}
186
187#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
188pub enum ToggleState {
189    /// The "on" state of a toggleable element.
190    ///
191    /// Example:
192    ///     - A collasable list that is currently expanded
193    ///     - A toggle button that is currently on.
194    Toggled,
195    /// The "off" state of a toggleable element.
196    ///
197    /// Example:
198    ///     - A collasable list that is currently collapsed
199    ///     - A toggle button that is currently off.
200    #[default]
201    NotToggled,
202}
203
204impl From<Toggleable> for ToggleState {
205    fn from(toggleable: Toggleable) -> Self {
206        match toggleable {
207            Toggleable::Toggleable(state) => state,
208            Toggleable::NotToggleable => ToggleState::NotToggled,
209        }
210    }
211}
212
213impl From<bool> for ToggleState {
214    fn from(toggled: bool) -> Self {
215        if toggled {
216            ToggleState::Toggled
217        } else {
218            ToggleState::NotToggled
219        }
220    }
221}