Skip to content

Commit a6101fc

Browse files
committed
Fix theme preference not being restored correctly
Using `set_visuals(Visuals::dark())` in `main()` somehow interfered badly with the theme switching code such that a light theme was not restored properly. Instead, the correct function to set the theme on startup is `set_theme()` and we should pass in the saved perference instead of hard-coding dark-mode. With these changes, all of the theme preferences work correctly and are restored correctly.
1 parent 6727350 commit a6101fc

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::gui::{load_gui_settings, GuiCommand, MyApp, RIGHT_PANEL_WIDTH};
1010
use crate::io::{open_from_csv, save_to_csv, FileOptions};
1111
use crate::serial::{load_serial_settings, serial_devices_thread, serial_thread, Device};
1212
use crossbeam_channel::{select, Receiver, Sender};
13-
use eframe::egui::{vec2, ViewportBuilder, Visuals};
13+
use eframe::egui::{vec2, ViewportBuilder};
1414
use eframe::{egui, icon_data};
1515
use egui_plot::PlotPoint;
1616
use preferences::AppInfo;
@@ -349,7 +349,7 @@ fn main() {
349349
let mut fonts = egui::FontDefinitions::default();
350350
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
351351
ctx.egui_ctx.set_fonts(fonts);
352-
ctx.egui_ctx.set_visuals(Visuals::dark());
352+
ctx.egui_ctx.set_theme(gui_settings.theme_preference);
353353
egui_extras::install_image_loaders(&ctx.egui_ctx);
354354

355355
let repaint_signal = ctx.egui_ctx.clone();

src/settings_window.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::gui::GuiSettingsContainer;
22
#[cfg(feature = "self_update")]
33
use crate::update::{check_update, update};
44
use eframe::egui;
5-
use eframe::egui::{Align2, InnerResponse, Vec2, Visuals};
5+
use eframe::egui::{Align2, InnerResponse, Vec2};
66
use egui_theme_switch::ThemeSwitch;
77
#[cfg(feature = "self_update")]
88
use self_update::restart::restart;
@@ -32,7 +32,7 @@ pub fn settings_window(
3232
{
3333
ui.ctx().set_theme(gui_conf.theme_preference);
3434
};
35-
gui_conf.dark_mode = ui.visuals() == &Visuals::dark();
35+
gui_conf.dark_mode = ui.ctx().theme() == egui::Theme::Dark;
3636

3737
ui.end_row();
3838
ui.end_row();

0 commit comments

Comments
 (0)