color.rs

 1use gpui::{Hsla, WindowContext};
 2use theme::ActiveTheme;
 3
 4/// Sets a color that has a consistent meaning across all themes.
 5#[derive(Debug, Default, PartialEq, Copy, Clone)]
 6pub enum Color {
 7    #[default]
 8    Default,
 9    Accent,
10    Created,
11    Deleted,
12    Disabled,
13    Error,
14    Hidden,
15    Hint,
16    Info,
17    Modified,
18    Conflict,
19    Ignored,
20    Muted,
21    Placeholder,
22    Player(u32),
23    Selected,
24    Success,
25    Warning,
26    Custom(Hsla),
27}
28
29impl Color {
30    pub fn color(&self, cx: &WindowContext) -> Hsla {
31        match self {
32            Color::Default => cx.theme().colors().text,
33            Color::Muted => cx.theme().colors().text_muted,
34            Color::Created => cx.theme().status().created,
35            Color::Modified => cx.theme().status().modified,
36            Color::Conflict => cx.theme().status().conflict,
37            Color::Ignored => cx.theme().status().ignored,
38            Color::Deleted => cx.theme().status().deleted,
39            Color::Disabled => cx.theme().colors().text_disabled,
40            Color::Hidden => cx.theme().status().hidden,
41            Color::Hint => cx.theme().status().hint,
42            Color::Info => cx.theme().status().info,
43            Color::Placeholder => cx.theme().colors().text_placeholder,
44            Color::Accent => cx.theme().colors().text_accent,
45            Color::Player(i) => cx.theme().styles.player.color_for_participant(*i).cursor,
46            Color::Error => cx.theme().status().error,
47            Color::Selected => cx.theme().colors().text_accent,
48            Color::Success => cx.theme().status().success,
49            Color::Warning => cx.theme().status().warning,
50            Color::Custom(color) => *color,
51        }
52    }
53}