Skip to content

Commit

Permalink
Fixed theme switching.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Dec 22, 2024
1 parent 32de05b commit 4843872
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 12 additions & 0 deletions crates/icy_term/src/data/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ impl Options {
Ok(Options::default())
}

pub(crate) fn get_theme(&self) -> egui::ThemePreference {
if let Some(dark_mode) = self.is_dark_mode {
if dark_mode {
egui::ThemePreference::Dark
} else {
egui::ThemePreference::Light
}
} else {
egui::ThemePreference::System
}
}

/// Returns the store options of this [`Options`].
///
/// # Errors
Expand Down
8 changes: 1 addition & 7 deletions crates/icy_term/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ impl MainWindow {
// #[cfg(target_arch = "wasm32")]
let is_fullscreen_mode = false;

// try to detect dark vs light mode from the host system; default to dark
let is_dark = if let Some(dark_mode) = &options.is_dark_mode {
*dark_mode
} else {
dark_light::detect() != dark_light::Mode::Light
};
let ctx: &egui::Context = &cc.egui_ctx;
ctx.set_visuals(if is_dark { egui::Visuals::dark() } else { egui::Visuals::light() });
ctx.set_theme(options.get_theme());

let mut initial_upload_directory = None;

Expand Down

0 comments on commit 4843872

Please sign in to comment.