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