Skip to content

Commit

Permalink
fix: theme is not applied on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed May 4, 2023
1 parent 8b86c02 commit 95c483c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl eframe::App for TypeFastApp {
egui::ScrollArea::vertical()
.id_source("all")
.show(ui, |ui| {
self.settings.set_new_theme(ctx);
self.type_state
.render(ui, &mut self.score, &mut self.settings);

Expand Down
16 changes: 13 additions & 3 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,32 @@ use crate::{
pub struct TFSetting {
pub command: String,
last_command: String,
last_theme: TFTheme,
theme: TFTheme,
#[serde(skip)]
pub level: Algorithm,
pub size: u32,
level_changed: bool,
}

#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq)]
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Clone, Copy)]

pub enum TFTheme {
Macchiato,
Frappe,
Latte,
Mocha,
Default,
}

impl TFTheme {
pub fn to_cat_theme(&self) -> catppuccin_egui::Theme {
pub fn to_cat_theme(self) -> catppuccin_egui::Theme {
match self {
TFTheme::Macchiato => catppuccin_egui::MACCHIATO,
TFTheme::Frappe => catppuccin_egui::FRAPPE,
TFTheme::Latte => catppuccin_egui::LATTE,
TFTheme::Mocha => catppuccin_egui::MOCHA,
TFTheme::Default => catppuccin_egui::MACCHIATO,
}
}
}
Expand All @@ -51,6 +54,7 @@ impl Default for TFSetting {
level: ALGS[0],
size: 2,
level_changed: false,
last_theme: TFTheme::Default,
theme: TFTheme::Macchiato,
}
}
Expand Down Expand Up @@ -98,8 +102,14 @@ impl TFSetting {
ui.selectable_value(&mut self.theme, TFTheme::Latte, "Latte");
ui.selectable_value(&mut self.theme, TFTheme::Mocha, "Mocha");
});
self.set_new_theme(ctx);
}

catppuccin_egui::set_theme(ctx, self.theme.to_cat_theme());
pub fn set_new_theme(&mut self, ctx: &egui::Context) {
if self.last_theme != self.theme {
catppuccin_egui::set_theme(ctx, self.theme.to_cat_theme());
self.last_theme = self.theme
}
}

pub fn notify_help(&mut self, text: &str) {
Expand Down

0 comments on commit 95c483c

Please sign in to comment.