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    /// Rerun on every light/dark switch; the [`crate::Brand`] applies to what it returns.
21    fn set_palette(&mut self, build: impl Fn(crate::Appearance) -> crate::Theme + 'static);
22
23    /// Sets the shared type ladder’s base size in points and refreshes windows.
24    fn set_base_text_size(&mut self, points: f32);
25}
26
27impl AppExt for App {
28    fn brand(&self) -> crate::Brand {
29        crate::brand::brand(self)
30    }
31
32    fn set_brand(&mut self, brand: crate::Brand) {
33        crate::brand::set_brand(brand, self)
34    }
35
36    fn appearance_mode(&self) -> crate::appearance::AppearanceMode {
37        crate::appearance::mode(self)
38    }
39
40    fn set_appearance_mode(&mut self, mode: crate::appearance::AppearanceMode) {
41        crate::appearance::set_mode(mode, self)
42    }
43
44    fn set_palette(&mut self, build: impl Fn(crate::Appearance) -> crate::Theme + 'static) {
45        crate::theme::install::set_palette(build, self)
46    }
47
48    fn set_base_text_size(&mut self, points: f32) {
49        crate::theme::typography::set_base_text_size(points, self)
50    }
51}