color.rs

  1use gpui::{App, Hsla};
  2use theme::ActiveTheme;
  3
  4/// Sets a color that has a consistent meaning across all themes.
  5#[derive(Debug, Default, Eq, PartialEq, Copy, Clone)]
  6pub enum Color {
  7    #[default]
  8    /// The default text color. Might be known as "foreground" or "primary" in
  9    /// some theme systems.
 10    ///
 11    /// For less emphasis, consider using [`Color::Muted`] or [`Color::Hidden`].
 12    Default,
 13    /// A text color used for accents, such as links or highlights.
 14    Accent,
 15    /// A color used to indicate a conflict, such as a version control merge conflict, or a conflict between a file in the editor and the file system.
 16    Conflict,
 17    /// A color used to indicate a newly created item, such as a new file in
 18    /// version control, or a new file on disk.
 19    Created,
 20    /// It is highly, HIGHLY recommended not to use this! Using this color
 21    /// means detaching it from any semantic meaning across themes.
 22    ///
 23    /// A custom color specified by an HSLA value.
 24    Custom(Hsla),
 25    /// A color used for all debugger UI elements.
 26    Debugger,
 27    /// A color used to indicate a deleted item, such as a file removed from version control.
 28    Deleted,
 29    /// A color used for disabled UI elements or text, like a disabled button or menu item.
 30    Disabled,
 31    /// A color used to indicate an error condition, or something the user
 32    /// cannot do. In very rare cases, it might be used to indicate dangerous or
 33    /// destructive action.
 34    Error,
 35    /// A color used for elements that represent something that is hidden, like
 36    /// a hidden file, or an element that should be visually de-emphasized.
 37    Hidden,
 38    /// A color used for hint or suggestion text, often a blue color. Use this
 39    /// color to represent helpful, or semantically neutral information.
 40    Hint,
 41    /// A color used for items that are intentionally ignored, such as files ignored by version control.
 42    Ignored,
 43    /// A color used for informational messages or status indicators, often a blue color.
 44    Info,
 45    /// A color used to indicate a modified item, such as an edited file, or a modified entry in version control.
 46    Modified,
 47    /// A color used for text or UI elements that should be visually muted or de-emphasized.
 48    ///
 49    /// For more emphasis, consider using [`Color::Default`].
 50    ///
 51    /// For less emphasis, consider using [`Color::Hidden`].
 52    Muted,
 53    /// A color used for placeholder text in input fields.
 54    Placeholder,
 55    /// A color associated with a specific player number.
 56    Player(u32),
 57    /// A color used to indicate selected text or UI elements.
 58    Selected,
 59    /// A color used to indicate a successful operation or status.
 60    Success,
 61    /// A version control color used to indicate a newly added file or content in version control.
 62    VersionControlAdded,
 63    /// A version control color used to indicate conflicting changes that need resolution.
 64    VersionControlConflict,
 65    /// A version control color used to indicate a file or content that has been deleted in version control.
 66    VersionControlDeleted,
 67    /// A version control color used to indicate files or content that is being ignored by version control.
 68    VersionControlIgnored,
 69    /// A version control color used to indicate modified files or content in version control.
 70    VersionControlModified,
 71    /// A color used to indicate a warning condition.
 72    Warning,
 73}
 74
 75impl Color {
 76    /// Returns the Color's HSLA value.
 77    pub fn color(&self, cx: &App) -> Hsla {
 78        match self {
 79            Color::Default => cx.theme().colors().text,
 80            Color::Muted => cx.theme().colors().text_muted,
 81            Color::Created => cx.theme().status().created,
 82            Color::Modified => cx.theme().status().modified,
 83            Color::Conflict => cx.theme().status().conflict,
 84            Color::Ignored => cx.theme().status().ignored,
 85            Color::Debugger => cx.theme().colors().debugger_accent,
 86            Color::Deleted => cx.theme().status().deleted,
 87            Color::Disabled => cx.theme().colors().text_disabled,
 88            Color::Hidden => cx.theme().status().hidden,
 89            Color::Hint => cx.theme().status().hint,
 90            Color::Info => cx.theme().status().info,
 91            Color::Placeholder => cx.theme().colors().text_placeholder,
 92            Color::Accent => cx.theme().colors().text_accent,
 93            Color::Player(i) => cx.theme().styles.player.color_for_participant(*i).cursor,
 94            Color::Error => cx.theme().status().error,
 95            Color::Selected => cx.theme().colors().text_accent,
 96            Color::Success => cx.theme().status().success,
 97            Color::VersionControlAdded => cx.theme().colors().version_control_added,
 98            Color::VersionControlConflict => cx.theme().colors().version_control_conflict,
 99            Color::VersionControlDeleted => cx.theme().colors().version_control_deleted,
100            Color::VersionControlIgnored => cx.theme().colors().version_control_ignored,
101            Color::VersionControlModified => cx.theme().colors().version_control_modified,
102            Color::Warning => cx.theme().status().warning,
103            Color::Custom(color) => *color,
104        }
105    }
106}
107
108impl From<Hsla> for Color {
109    fn from(color: Hsla) -> Self {
110        Color::Custom(color)
111    }
112}