prelude.rs

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