theme: Simplify init (#237)
This commit is contained in:
parent
cf551654fe
commit
9388b88f59
3 changed files with 8 additions and 12 deletions
|
|
@ -31,7 +31,6 @@ actions!(workspace, [Open, CloseWindow]);
|
||||||
pub fn init(_app_state: Arc<AppState>, cx: &mut AppContext) {
|
pub fn init(_app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||||
cx.on_action(|_action: &Open, _cx: &mut AppContext| {});
|
cx.on_action(|_action: &Open, _cx: &mut AppContext| {});
|
||||||
|
|
||||||
Theme::init(cx);
|
|
||||||
ui::init(cx);
|
ui::init(cx);
|
||||||
story::init(cx);
|
story::init(cx);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ pub use svg_img::*;
|
||||||
|
|
||||||
/// Initialize the UI module.
|
/// Initialize the UI module.
|
||||||
pub fn init(cx: &mut gpui::AppContext) {
|
pub fn init(cx: &mut gpui::AppContext) {
|
||||||
|
theme::init(cx);
|
||||||
context_menu::init(cx);
|
context_menu::init(cx);
|
||||||
date_picker::init(cx);
|
date_picker::init(cx);
|
||||||
dock::init(cx);
|
dock::init(cx);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@ use gpui::{
|
||||||
ViewContext, WindowAppearance, WindowContext,
|
ViewContext, WindowAppearance, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn init(cx: &mut AppContext) {
|
||||||
|
Theme::sync_system_appearance(cx)
|
||||||
|
}
|
||||||
|
|
||||||
pub trait ActiveTheme {
|
pub trait ActiveTheme {
|
||||||
fn theme(&self) -> &Theme;
|
fn theme(&self) -> &Theme;
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +332,7 @@ impl Theme {
|
||||||
impl From<Colors> for Theme {
|
impl From<Colors> for Theme {
|
||||||
fn from(colors: Colors) -> Self {
|
fn from(colors: Colors) -> Self {
|
||||||
Theme {
|
Theme {
|
||||||
mode: ThemeMode::Dark,
|
mode: ThemeMode::default(),
|
||||||
transparent: Hsla::transparent_black(),
|
transparent: Hsla::transparent_black(),
|
||||||
font_size: 14.0,
|
font_size: 14.0,
|
||||||
font_family: if cfg!(target_os = "macos") {
|
font_family: if cfg!(target_os = "macos") {
|
||||||
|
|
@ -397,9 +401,10 @@ impl From<Colors> for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, PartialOrd, Eq)]
|
#[derive(Debug, Default, PartialEq, PartialOrd, Eq)]
|
||||||
pub enum ThemeMode {
|
pub enum ThemeMode {
|
||||||
Light,
|
Light,
|
||||||
|
#[default]
|
||||||
Dark,
|
Dark,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,15 +415,6 @@ impl ThemeMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
fn new() -> Self {
|
|
||||||
Self::from(Colors::dark())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
|
||||||
cx.set_global(Theme::new());
|
|
||||||
Self::sync_system_appearance(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sync the theme with the system appearance
|
/// Sync the theme with the system appearance
|
||||||
pub fn sync_system_appearance(cx: &mut AppContext) {
|
pub fn sync_system_appearance(cx: &mut AppContext) {
|
||||||
match cx.window_appearance() {
|
match cx.window_appearance() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue