Skip to content

Commit

Permalink
add basic system theme option
Browse files Browse the repository at this point in the history
  • Loading branch information
nickolasclarke authored and jacksongoode committed Feb 7, 2024
1 parent c70ace5 commit 16bc21e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions psst-gui/src/data/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ impl Default for AudioQuality {
pub enum Theme {
Light,
Dark,
System
}

impl Default for Theme {
Expand Down
2 changes: 1 addition & 1 deletion psst-gui/src/ui/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn general_tab_widget() -> impl Widget<AppState> {
.with_child(Label::new("Theme").with_font(theme::UI_FONT_MEDIUM))
.with_spacer(theme::grid(2.0))
.with_child(
RadioGroup::column(vec![("Light", Theme::Light), ("Dark", Theme::Dark)])
RadioGroup::column(vec![("Light", Theme::Light), ("Dark", Theme::Dark), ("System", Theme::System)])
.lens(AppState::config.then(Config::theme)),
);

Expand Down
15 changes: 15 additions & 0 deletions psst-gui/src/ui/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn setup(env: &mut Env, state: &AppState) {
match state.config.theme {
Theme::Light => setup_light_theme(env),
Theme::Dark => setup_dark_theme(env),
Theme::System => setup_system_theme(env),
};

env.set(WINDOW_BACKGROUND_COLOR, env.get(GREY_700));
Expand All @@ -69,6 +70,11 @@ pub fn setup(env: &mut Env, state: &AppState) {
env.set(BUTTON_LIGHT, env.get(GREY_600));
env.set(BUTTON_DARK, env.get(GREY_700));
}
//TODO: fix this?
Theme::System => {
env.set(BUTTON_LIGHT, env.get(GREY_600));
env.set(BUTTON_DARK, env.get(GREY_700));
}
}

env.set(BORDER_LIGHT, env.get(GREY_400));
Expand Down Expand Up @@ -165,3 +171,12 @@ fn setup_dark_theme(env: &mut Env) {
env.set(LINK_ACTIVE_COLOR, Color::rgba(1.0, 1.0, 1.0, 0.025));
env.set(LINK_COLD_COLOR, Color::rgba(1.0, 1.0, 1.0, 0.0));
}

fn setup_system_theme(env: &mut Env) {
let current_theme = dark_light::detect();
if current_theme == dark_light::Mode::Dark {
setup_dark_theme(env);
} else {
setup_light_theme(env);
}
}

0 comments on commit 16bc21e

Please sign in to comment.