prelude.rs

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