diff --git a/desktop/src/app.rs b/desktop/src/app.rs index 9ca91ecef..5573fbf2b 100644 --- a/desktop/src/app.rs +++ b/desktop/src/app.rs @@ -538,6 +538,10 @@ impl App { return; } + winit::event::Event::UserEvent(RuffleEvent::ThemeChanged(theme)) => { + self.gui.borrow().set_theme(theme); + } + _ => (), } diff --git a/desktop/src/custom_event.rs b/desktop/src/custom_event.rs index bde562cb6..50daa0d29 100644 --- a/desktop/src/custom_event.rs +++ b/desktop/src/custom_event.rs @@ -1,6 +1,7 @@ //! Custom event type for desktop ruffle use crate::player::LaunchOptions; +use winit::window::Theme; /// User-defined events. pub enum RuffleEvent { @@ -24,4 +25,7 @@ pub enum RuffleEvent { /// The user selected an item in the right-click context menu. ContextMenuItemClicked(usize), + + /// System theme has changed. + ThemeChanged(Theme), } diff --git a/desktop/src/gui/controller.rs b/desktop/src/gui/controller.rs index 5a7f7c44b..021f7be9a 100644 --- a/desktop/src/gui/controller.rs +++ b/desktop/src/gui/controller.rs @@ -138,6 +138,14 @@ impl GuiController { }) } + pub fn set_theme(&self, theme: Theme) { + self.egui_winit.egui_ctx().set_visuals(match theme { + Theme::Light => egui::Visuals::light(), + Theme::Dark => egui::Visuals::dark(), + }); + self.window.request_redraw(); + } + pub fn descriptors(&self) -> &Arc { &self.descriptors } @@ -178,11 +186,7 @@ impl GuiController { } if let WindowEvent::ThemeChanged(theme) = &event { - let visuals = match theme { - Theme::Dark => egui::Visuals::dark(), - Theme::Light => egui::Visuals::light(), - }; - self.egui_winit.egui_ctx().set_visuals(visuals); + self.set_theme(*theme); } if matches!(