From 9fbb76968caab02f355eb9e960d4b7572d28e39e Mon Sep 17 00:00:00 2001 From: ardocrat Date: Mon, 3 Jun 2024 18:34:13 +0300 Subject: [PATCH] desktop: glow renderer fallback support --- Cargo.toml | 2 +- src/gui/platform/desktop/mod.rs | 1 + src/lib.rs | 16 ++++++++++------ src/main.rs | 12 ++++++++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dc8ff84..68581ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -112,4 +112,4 @@ jni = "0.21.1" android-activity = { version = "0.6.0", features = ["game-activity"] } wgpu = "0.19.1" winit = { version = "0.29.15", features = ["android-game-activity"] } -eframe = { version = "0.27.2", features = ["wgpu", "android-game-activity"] } \ No newline at end of file +eframe = { version = "0.27.2", features = ["wgpu", "glow", "android-game-activity"] } \ No newline at end of file diff --git a/src/gui/platform/desktop/mod.rs b/src/gui/platform/desktop/mod.rs index f5dc3df..2d242f6 100644 --- a/src/gui/platform/desktop/mod.rs +++ b/src/gui/platform/desktop/mod.rs @@ -27,6 +27,7 @@ use rfd::FileDialog; use crate::gui::platform::PlatformCallbacks; /// Desktop platform related actions. +#[derive(Clone)] pub struct Desktop { /// Flag to check if camera stop is needed. stop_camera: Arc, diff --git a/src/lib.rs b/src/lib.rs index 6640af8..6cadcbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ #[macro_use] extern crate rust_i18n; +use eframe::NativeOptions; use egui::{Context, Stroke}; #[cfg(target_os = "android")] @@ -68,7 +69,7 @@ fn android_main(app: AndroidApp) { let width = app.config().screen_width_dp().unwrap() as f32; let height = app.config().screen_height_dp().unwrap() as f32; let size = egui::emath::vec2(width, height); - let mut options = eframe::NativeOptions { + let mut options = NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size(size), ..Default::default() }; @@ -89,7 +90,7 @@ fn android_main(app: AndroidApp) { })); let app = PlatformApp::new(platform); - start(options, app_creator(app)); + start(options, app_creator(app)).unwrap(); } /// Check if system is using dark theme. @@ -116,9 +117,12 @@ pub fn app_creator(app: PlatformApp) -> eframe::AppCreator } /// Entry point to start ui with [`eframe`]. -pub fn start(mut options: eframe::NativeOptions, app_creator: eframe::AppCreator) { - options.default_theme = eframe::Theme::Light; - options.renderer = eframe::Renderer::Wgpu; +pub fn start(mut options: NativeOptions, app_creator: eframe::AppCreator) -> eframe::Result<()> { + options.default_theme = if AppConfig::dark_theme().unwrap_or(false) { + eframe::Theme::Dark + } else { + eframe::Theme::Light + }; // Setup translations. setup_i18n(); // Start integrated node if needed. @@ -126,7 +130,7 @@ pub fn start(mut options: eframe::NativeOptions, app_creator: eframe::AppCreator Node::start(); } // Launch graphical interface. - eframe::run_native("Grim", options, app_creator).unwrap(); + eframe::run_native("Grim", options, app_creator) } /// Setup application [`egui::Style`] and [`egui::Visuals`]. diff --git a/src/main.rs b/src/main.rs index a09ca5c..6e4c7b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,9 +69,17 @@ fn real_main() { viewport = viewport.with_position(pos2(x, y)); } - let options = eframe::NativeOptions { + let mut options = eframe::NativeOptions { viewport, ..Default::default() }; - grim::start(options, grim::app_creator(PlatformApp::new(platform))); + options.renderer = eframe::Renderer::Wgpu; + match grim::start(options.clone(), grim::app_creator(PlatformApp::new(platform.clone()))) { + Ok(_) => {} + Err(_) => { + // Start with Glow renderer on error. + options.renderer = eframe::Renderer::Glow; + grim::start(options, grim::app_creator(PlatformApp::new(platform))).unwrap(); + } + } } \ No newline at end of file