Skip to main content

theme/
app.rs

1//! App-owned configuration.
2
3use gpui::App;
4
5/// Configuration carried by the application. Import as `use theme::AppExt as _;`.
6pub trait AppExt {
7    /// Reads brand.
8    fn brand(&self) -> crate::Brand;
9
10    /// Installs a brand, rebuilds the palette and refreshes window backgrounds.
11    fn set_brand(&mut self, brand: crate::Brand);
12
13    /// Reads appearance mode.
14    fn appearance_mode(&self) -> crate::appearance::AppearanceMode;
15
16    /// Changes the preference after `appearance::init`; repaints if needed.
17    fn set_appearance_mode(&mut self, mode: crate::appearance::AppearanceMode);
18
19    /// Sets the palette builder. Install before `appearance::init`, or apply afterward.
20    fn set_palette(&mut self, build: impl Fn(crate::Appearance) -> crate::Theme + 'static);
21
22    /// Sets the shared type ladder’s base size in points and refreshes windows.
23    fn set_base_text_size(&mut self, points: f32);
24}
25
26impl AppExt for App {
27    fn brand(&self) -> crate::Brand {
28        crate::brand::brand(self)
29    }
30
31    fn set_brand(&mut self, brand: crate::Brand) {
32        crate::brand::set_brand(brand, self)
33    }
34
35    fn appearance_mode(&self) -> crate::appearance::AppearanceMode {
36        crate::appearance::mode(self)
37    }
38
39    fn set_appearance_mode(&mut self, mode: crate::appearance::AppearanceMode) {
40        crate::appearance::set_mode(mode, self)
41    }
42
43    fn set_palette(&mut self, build: impl Fn(crate::Appearance) -> crate::Theme + 'static) {
44        crate::theme::install::set_palette(build, self)
45    }
46
47    fn set_base_text_size(&mut self, points: f32) {
48        crate::theme::typography::set_base_text_size(points, self)
49    }
50}