1use crate::{rgb, Hsla, Rgba, WindowAppearance};
2
3#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
4/// The appearance of the base gpui colors, used to style gpui elements
5///
6/// Varies based on the system's current [WindowAppearance].
7pub enum DefaultThemeAppearance {
8 #[default]
9 /// Use the set of colors for light appearances
10 Light,
11 /// Use the set of colors for dark appearances
12 Dark,
13}
14
15impl From<WindowAppearance> for DefaultThemeAppearance {
16 fn from(appearance: WindowAppearance) -> Self {
17 match appearance {
18 WindowAppearance::Light | WindowAppearance::VibrantLight => Self::Light,
19 WindowAppearance::Dark | WindowAppearance::VibrantDark => Self::Dark,
20 }
21 }
22}
23
24/// Get the default colors for the given appearance
25pub fn colors(appearance: DefaultThemeAppearance) -> DefaultColors {
26 match appearance {
27 DefaultThemeAppearance::Light => DefaultColors::light(),
28 DefaultThemeAppearance::Dark => DefaultColors::dark(),
29 }
30}
31
32/// A collection of colors
33#[derive(Debug, Clone, Copy, PartialEq)]
34pub struct DefaultColors {
35 text: Rgba,
36 selected_text: Rgba,
37 background: Rgba,
38 disabled: Rgba,
39 selected: Rgba,
40 border: Rgba,
41 separator: Rgba,
42 container: Rgba,
43}
44
45impl DefaultColors {
46 /// Get the default light colors
47 pub fn dark() -> Self {
48 Self {
49 text: rgb(0xFFFFFF),
50 selected_text: rgb(0xFFFFFF),
51 disabled: rgb(0x565656),
52 selected: rgb(0x2457CA),
53 background: rgb(0x222222),
54 border: rgb(0x000000),
55 separator: rgb(0xD9D9D9),
56 container: rgb(0x262626),
57 }
58 }
59
60 /// Get the default dark colors
61 pub fn light() -> Self {
62 Self {
63 text: rgb(0x252525),
64 selected_text: rgb(0xFFFFFF),
65 background: rgb(0xFFFFFF),
66 disabled: rgb(0xB0B0B0),
67 selected: rgb(0x2A63D9),
68 border: rgb(0xD9D9D9),
69 separator: rgb(0xE6E6E6),
70 container: rgb(0xF4F5F5),
71 }
72 }
73}
74
75/// A default gpui color
76#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::EnumIter)]
77pub enum DefaultColor {
78 /// Text color
79 Text,
80 /// Selected text color
81 SelectedText,
82 /// Background color
83 Background,
84 /// Disabled color
85 Disabled,
86 /// Selected color
87 Selected,
88 /// Border color
89 Border,
90 /// Separator color
91 Separator,
92 /// Container color
93 Container,
94}
95impl DefaultColor {
96 /// Get the Rgb color for the given color type
97 pub fn color(&self, colors: &DefaultColors) -> Rgba {
98 match self {
99 DefaultColor::Text => colors.text,
100 DefaultColor::SelectedText => colors.selected_text,
101 DefaultColor::Background => colors.background,
102 DefaultColor::Disabled => colors.disabled,
103 DefaultColor::Selected => colors.selected,
104 DefaultColor::Border => colors.border,
105 DefaultColor::Separator => colors.separator,
106 DefaultColor::Container => colors.container,
107 }
108 }
109
110 /// Get the Hsla color for the given color type
111 pub fn hsla(&self, colors: &DefaultColors) -> Hsla {
112 self.color(&colors).into()
113 }
114}