use gpui::{App, Global};
use crate::{
Appearance, paint,
theme::{Theme, layout},
};
impl Theme {
pub fn install(appearance: Appearance, cx: &mut App) {
let build = cx
.try_global::<Palette>()
.map_or(Self::for_appearance as fn(Appearance) -> Theme, |p| p.0);
let brand = crate::brand(cx);
let mut theme = build(appearance);
brand.apply(&mut theme);
layout::set_base_radius(brand.radius);
layout::set_frost(brand.glass);
Self::install_custom(theme, cx);
}
pub fn install_custom(theme: Theme, cx: &mut App) {
paint::set_current_appearance(theme.appearance);
paint::bump_generation();
cx.set_global(theme);
cx.refresh_windows();
}
pub fn of(cx: &App) -> &Theme {
cx.global::<Theme>()
}
}
struct Palette(fn(Appearance) -> Theme);
impl Global for Palette {}
pub fn set_palette(build: fn(Appearance) -> Theme, cx: &mut App) {
cx.set_global(Palette(build));
}