1pub mod color;
25pub mod fonts;
26pub mod palette;
27
28use std::sync::RwLock;
29
30use gpui_kit::component::{Theme, ThemeMode};
31use gpui_kit::{App, Pixels, Window, px, rgba};
32
33pub use color::{Colors, DATA, colors, contrast, data, mix, rgb8, rgb_hsla};
34pub use palette::{Accent, Palette, Rgb};
35
36pub const XS: f32 = 4.;
38pub const SM: f32 = 8.;
40pub const MD: f32 = 12.;
42pub const LG: f32 = 16.;
44pub const XL: f32 = 24.;
46pub const XXL: f32 = 32.;
48
49pub const FONT_SIZE: f32 = 15.;
51pub const FONT_RANGE: (f32, f32) = (12., 18.);
53
54pub const RADIUS_SM: f32 = 4.;
56pub const RADIUS: f32 = 6.;
58pub const RADIUS_LG: f32 = 8.;
60
61pub const PANE_GAP: f32 = 4.;
63pub const PANE_PADDING: f32 = 8.;
65
66pub const LABEL_W: f32 = 112.;
68pub const CONTROL_MIN_W: f32 = 140.;
70pub const TARGET_MIN: f32 = 24.;
72
73#[derive(Clone, Copy, Debug, PartialEq)]
75pub struct Look {
76 pub dark: bool,
78 pub palette: Palette,
80 pub accent: Option<Rgb>,
83 pub font_size: f32,
85}
86
87impl Look {
88 pub const fn new(palette: Palette) -> Self {
90 Look { dark: true, palette, accent: None, font_size: FONT_SIZE }
91 }
92
93 pub fn active_palette(&self) -> Palette {
95 match self.accent {
96 Some(rgb) => Palette::custom(rgb),
97 None => self.palette,
98 }
99 }
100
101 pub const fn with_dark(self, dark: bool) -> Self {
103 Look { dark, ..self }
104 }
105
106 pub const fn with_palette(self, palette: Palette) -> Self {
108 Look { palette, ..self }
109 }
110
111 pub const fn with_accent(self, accent: Option<Rgb>) -> Self {
113 Look { accent, ..self }
114 }
115
116 pub fn with_font_size(self, font_size: f32) -> Self {
118 Look { font_size: font_size.round().clamp(FONT_RANGE.0, FONT_RANGE.1), ..self }
119 }
120}
121
122impl Default for Look {
123 fn default() -> Self {
124 Look::new(Palette::LIME)
125 }
126}
127
128static LOOK: RwLock<Look> = RwLock::new(Look::new(Palette::LIME));
129
130pub fn set_look(look: Look) {
132 let look = look.with_font_size(look.font_size);
133 *LOOK.write().unwrap_or_else(|e| e.into_inner()) = look;
134}
135
136pub fn look() -> Look {
138 *LOOK.read().unwrap_or_else(|e| e.into_inner())
139}
140
141pub fn is_dark() -> bool {
143 look().dark
144}
145
146pub fn system_dark(window: &Window) -> bool {
148 use gpui_kit::WindowAppearance as W;
149 matches!(window.appearance(), W::Dark | W::VibrantDark)
150}
151
152pub fn use_look(look: Look, cx: &mut App) {
154 set_look(look);
155 apply(cx);
156}
157
158pub fn apply(cx: &mut App) {
161 let l = look();
162 Theme::change(if l.dark { ThemeMode::Dark } else { ThemeMode::Light }, None, cx);
163 let c = Colors::resolve(&l);
164 let (on_danger, on_success, on_warning) = (palette::best_text_on(c.danger), palette::best_text_on(c.success), palette::best_text_on(c.warning));
165 Theme::update(cx, |t| {
166 t.font_size = px(l.font_size);
167 t.radius = px(RADIUS);
168 t.radius_lg = px(RADIUS_LG);
169 t.shadow = true;
170 if fonts::loaded() {
171 t.font_family = fonts::UI.into();
172 t.mono_font_family = fonts::MONO.into();
173 }
174 t.mono_font_size = px((l.font_size - 2.).max(10.));
176 let mut code = (*t.highlight_theme).clone();
177 code.style.editor_background = Some(c.raised);
178 code.style.editor_gutter_background = Some(c.raised);
179 code.style.editor_foreground = Some(c.text);
180 code.style.editor_line_number = Some(c.text_muted);
181 code.style.editor_active_line_number = Some(c.text);
182 code.style.editor_active_line = Some(c.hover.opacity(0.5));
183 t.highlight_theme = std::sync::Arc::new(code);
184 let k = &mut t.colors;
185 k.background = c.panel;
186 k.foreground = c.text;
187 k.muted = c.raised;
188 k.muted_foreground = c.text_muted;
189 k.border = c.border;
190 k.input = c.hover;
191 k.ring = c.focus;
192 k.caret = c.text;
193 k.selection = c.accent.opacity(0.45);
194 k.popover = c.raised;
195 k.popover_foreground = c.text;
196 k.sidebar = c.chrome;
197 k.sidebar_foreground = c.text;
198 k.sidebar_border = c.border;
199 k.sidebar_accent = c.control;
200 k.sidebar_accent_foreground = c.text;
201 k.sidebar_primary = c.accent;
202 k.sidebar_primary_foreground = c.on_accent;
203 k.primary = c.accent;
204 k.primary_hover = c.accent_hover;
205 k.primary_active = c.accent;
206 k.primary_foreground = c.on_accent;
207 k.secondary = c.control;
208 k.secondary_hover = c.hover;
209 k.secondary_active = c.hover;
210 k.secondary_foreground = c.text;
211 k.accent = c.control;
212 k.accent_foreground = c.text;
213 k.title_bar = c.chrome;
214 k.title_bar_border = c.border;
215 k.tab_bar = c.chrome;
216 k.tab = c.chrome;
217 k.tab_active = c.panel;
218 k.tab_foreground = c.text_muted;
219 k.tab_active_foreground = c.text;
220 k.list = c.panel;
221 k.list_even = c.panel;
222 k.list_hover = c.control;
223 k.list_active = c.selection;
224 k.list_active_border = c.accent_mark;
225 k.list_head = c.raised;
226 k.table = c.panel;
227 k.table_even = c.raised;
228 k.table_head = c.raised;
229 k.table_head_foreground = c.text_muted;
230 k.table_active = c.selection;
231 k.table_active_border = c.accent_mark;
232 k.danger = c.danger;
233 k.danger_foreground = on_danger;
234 k.success = c.success;
235 k.success_foreground = on_success;
236 k.warning = c.warning;
237 k.warning_foreground = on_warning;
238 k.red = c.danger;
240 k.green = c.success;
241 k.info = c.info;
242 k.link = c.accent_mark;
243 k.scrollbar = rgba(0x00000000).into();
244 k.scrollbar_thumb = if l.dark { rgba(0xffffff33).into() } else { rgba(0x00000033).into() };
245 k.scrollbar_thumb_hover = if l.dark { rgba(0xffffff55).into() } else { rgba(0x00000055).into() };
246 k.window_border = c.border;
247 k.overlay = rgba(0x00000080).into();
248 k.drag_border = c.accent_mark;
249 k.drop_target = c.selection;
250 k.chart_grid = c.grid;
251 });
252}
253
254pub fn sp(v: f32) -> Pixels {
256 px(v)
257}