prelude.rs

  1pub use gpui2::{
  2    div, Element, ElementId, IntoAnyElement, ParentElement, SharedString, StatefulInteractive,
  3    StatelessInteractive, Styled, ViewContext, WindowContext,
  4};
  5
  6pub use crate::color::*;
  7pub use crate::elevation::*;
  8use crate::settings::user_settings;
  9pub use crate::{old_theme, theme, ButtonVariant, ElementExt, Theme};
 10
 11use gpui2::{rems, Hsla, Rems};
 12use strum::EnumIter;
 13
 14pub fn ui_size(cx: &mut WindowContext, size: f32) -> Rems {
 15    const UI_SCALE_RATIO: f32 = 0.875;
 16
 17    let settings = user_settings(cx);
 18
 19    rems(*settings.ui_scale * UI_SCALE_RATIO * size)
 20}
 21
 22#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 23pub enum FileSystemStatus {
 24    #[default]
 25    None,
 26    Conflict,
 27    Deleted,
 28}
 29
 30impl FileSystemStatus {
 31    pub fn to_string(&self) -> String {
 32        match self {
 33            Self::None => "None".to_string(),
 34            Self::Conflict => "Conflict".to_string(),
 35            Self::Deleted => "Deleted".to_string(),
 36        }
 37    }
 38}
 39
 40#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 41pub enum GitStatus {
 42    #[default]
 43    None,
 44    Created,
 45    Modified,
 46    Deleted,
 47    Conflict,
 48    Renamed,
 49}
 50
 51impl GitStatus {
 52    pub fn to_string(&self) -> String {
 53        match self {
 54            Self::None => "None".to_string(),
 55            Self::Created => "Created".to_string(),
 56            Self::Modified => "Modified".to_string(),
 57            Self::Deleted => "Deleted".to_string(),
 58            Self::Conflict => "Conflict".to_string(),
 59            Self::Renamed => "Renamed".to_string(),
 60        }
 61    }
 62
 63    pub fn hsla(&self, cx: &WindowContext) -> Hsla {
 64        let theme = theme(cx);
 65
 66        match self {
 67            Self::None => theme.transparent,
 68            Self::Created => theme.git_created,
 69            Self::Modified => theme.git_modified,
 70            Self::Deleted => theme.git_deleted,
 71            Self::Conflict => theme.git_conflict,
 72            Self::Renamed => theme.git_renamed,
 73        }
 74    }
 75}
 76
 77#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 78pub enum DiagnosticStatus {
 79    #[default]
 80    None,
 81    Error,
 82    Warning,
 83    Info,
 84}
 85
 86#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 87pub enum IconSide {
 88    #[default]
 89    Left,
 90    Right,
 91}
 92
 93#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
 94pub enum OrderMethod {
 95    #[default]
 96    Ascending,
 97    Descending,
 98    MostRecent,
 99}
100
101#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
102pub enum Shape {
103    #[default]
104    Circle,
105    RoundedRectangle,
106}
107
108#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
109pub enum DisclosureControlVisibility {
110    #[default]
111    OnHover,
112    Always,
113}
114
115#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
116pub enum DisclosureControlStyle {
117    /// Shows the disclosure control only when hovered where possible.
118    ///
119    /// More compact, but not available everywhere.
120    ChevronOnHover,
121    /// Shows an icon where possible, otherwise shows a chevron.
122    ///
123    /// For example, in a file tree a folder or file icon is shown
124    /// instead of a chevron
125    Icon,
126    /// Always shows a chevron.
127    Chevron,
128    /// Completely hides the disclosure control where possible.
129    None,
130}
131
132#[derive(Debug, PartialEq, Eq, Clone, Copy, EnumIter)]
133pub enum OverflowStyle {
134    Hidden,
135    Wrap,
136}
137
138#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
139pub enum InteractionState {
140    #[default]
141    Enabled,
142    Hovered,
143    Active,
144    Focused,
145    Disabled,
146}
147
148impl InteractionState {
149    pub fn if_enabled(&self, enabled: bool) -> Self {
150        if enabled {
151            *self
152        } else {
153            InteractionState::Disabled
154        }
155    }
156}
157
158#[derive(Default, PartialEq)]
159pub enum SelectedState {
160    #[default]
161    Unselected,
162    PartiallySelected,
163    Selected,
164}
165
166#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
167pub enum Toggleable {
168    Toggleable(ToggleState),
169    #[default]
170    NotToggleable,
171}
172
173impl Toggleable {
174    pub fn is_toggled(&self) -> bool {
175        match self {
176            Self::Toggleable(ToggleState::Toggled) => true,
177            _ => false,
178        }
179    }
180}
181
182impl From<ToggleState> for Toggleable {
183    fn from(state: ToggleState) -> Self {
184        Self::Toggleable(state)
185    }
186}
187
188#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
189pub enum ToggleState {
190    /// The "on" state of a toggleable element.
191    ///
192    /// Example:
193    ///     - A collasable list that is currently expanded
194    ///     - A toggle button that is currently on.
195    Toggled,
196    /// The "off" state of a toggleable element.
197    ///
198    /// Example:
199    ///     - A collasable list that is currently collapsed
200    ///     - A toggle button that is currently off.
201    #[default]
202    NotToggled,
203}
204
205impl From<Toggleable> for ToggleState {
206    fn from(toggleable: Toggleable) -> Self {
207        match toggleable {
208            Toggleable::Toggleable(state) => state,
209            Toggleable::NotToggleable => ToggleState::NotToggled,
210        }
211    }
212}
213
214impl From<bool> for ToggleState {
215    fn from(toggled: bool) -> Self {
216        if toggled {
217            ToggleState::Toggled
218        } else {
219            ToggleState::NotToggled
220        }
221    }
222}