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, rgb_hsla, rgb8};
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) =
165 (palette::best_text_on(c.danger), palette::best_text_on(c.success), palette::best_text_on(c.warning));
166 Theme::update(cx, |t| {
167 t.font_size = px(l.font_size);
168 t.radius = px(RADIUS);
169 t.radius_lg = px(RADIUS_LG);
170 t.shadow = true;
171 if fonts::loaded() {
172 t.font_family = fonts::UI.into();
173 t.mono_font_family = fonts::MONO.into();
174 }
175 t.mono_font_size = px((l.font_size - 2.).max(10.));
177 let mut code = (*t.highlight_theme).clone();
178 code.style.editor_background = Some(c.raised);
179 code.style.editor_gutter_background = Some(c.raised);
180 code.style.editor_foreground = Some(c.text);
181 code.style.editor_line_number = Some(c.text_muted);
182 code.style.editor_active_line_number = Some(c.text);
183 code.style.editor_active_line = Some(c.hover.opacity(0.5));
184 t.highlight_theme = std::sync::Arc::new(code);
185 let k = &mut t.colors;
186 k.background = c.panel;
187 k.foreground = c.text;
188 k.muted = c.raised;
189 k.muted_foreground = c.text_muted;
190 k.border = c.border;
191 k.input = c.hover;
192 k.ring = c.focus;
193 k.caret = c.text;
194 k.selection = c.accent.opacity(0.45);
195 k.popover = c.raised;
196 k.popover_foreground = c.text;
197 k.sidebar = c.chrome;
198 k.sidebar_foreground = c.text;
199 k.sidebar_border = c.border;
200 k.sidebar_accent = c.control;
201 k.sidebar_accent_foreground = c.text;
202 k.sidebar_primary = c.accent;
203 k.sidebar_primary_foreground = c.on_accent;
204 k.primary = c.accent;
205 k.primary_hover = c.accent_hover;
206 k.primary_active = c.accent;
207 k.primary_foreground = c.on_accent;
208 k.secondary = c.control;
209 k.secondary_hover = c.hover;
210 k.secondary_active = c.hover;
211 k.secondary_foreground = c.text;
212 k.accent = c.control;
213 k.accent_foreground = c.text;
214 k.title_bar = c.chrome;
215 k.title_bar_border = c.border;
216 k.tab_bar = c.chrome;
217 k.tab = c.chrome;
218 k.tab_active = c.panel;
219 k.tab_foreground = c.text_muted;
220 k.tab_active_foreground = c.text;
221 k.list = c.panel;
222 k.list_even = c.panel;
223 k.list_hover = c.control;
224 k.list_active = c.selection;
225 k.list_active_border = c.accent_mark;
226 k.list_head = c.raised;
227 k.table = c.panel;
228 k.table_even = c.raised;
229 k.table_head = c.raised;
230 k.table_head_foreground = c.text_muted;
231 k.table_active = c.selection;
232 k.table_active_border = c.accent_mark;
233 k.danger = c.danger;
234 k.danger_foreground = on_danger;
235 k.success = c.success;
236 k.success_foreground = on_success;
237 k.warning = c.warning;
238 k.warning_foreground = on_warning;
239 k.red = c.danger;
241 k.green = c.success;
242 k.info = c.info;
243 k.link = c.accent_mark;
244 k.scrollbar = rgba(0x00000000).into();
245 k.scrollbar_thumb = if l.dark { rgba(0xffffff33).into() } else { rgba(0x00000033).into() };
246 k.scrollbar_thumb_hover = if l.dark { rgba(0xffffff55).into() } else { rgba(0x00000055).into() };
247 k.window_border = c.border;
248 k.overlay = rgba(0x00000080).into();
249 k.drag_border = c.accent_mark;
250 k.drop_target = c.selection;
251 k.chart_grid = c.grid;
252 });
253}
254
255pub fn sp(v: f32) -> Pixels {
257 px(v)
258}