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 color used to indicate a warning condition.
62 Warning,
63}
64
65impl Color {
66 /// Returns the Color's HSLA value.
67 pub fn color(&self, cx: &App) -> Hsla {
68 match self {
69 Color::Default => cx.theme().colors().text,
70 Color::Muted => cx.theme().colors().text_muted,
71 Color::Created => cx.theme().status().created,
72 Color::Modified => cx.theme().status().modified,
73 Color::Conflict => cx.theme().status().conflict,
74 Color::Ignored => cx.theme().status().ignored,
75 Color::Debugger => cx.theme().colors().debugger_accent,
76 Color::Deleted => cx.theme().status().deleted,
77 Color::Disabled => cx.theme().colors().text_disabled,
78 Color::Hidden => cx.theme().status().hidden,
79 Color::Hint => cx.theme().status().hint,
80 Color::Info => cx.theme().status().info,
81 Color::Placeholder => cx.theme().colors().text_placeholder,
82 Color::Accent => cx.theme().colors().text_accent,
83 Color::Player(i) => cx.theme().styles.player.color_for_participant(*i).cursor,
84 Color::Error => cx.theme().status().error,
85 Color::Selected => cx.theme().colors().text_accent,
86 Color::Success => cx.theme().status().success,
87 Color::Warning => cx.theme().status().warning,
88 Color::Custom(color) => *color,
89 }
90 }
91}
92
93impl From<Hsla> for Color {
94 fn from(color: Hsla) -> Self {
95 Color::Custom(color)
96 }
97}