From ba9d1e446c800def83e63844ca5b0c15dd75c0cd Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 20 Aug 2022 10:04:12 +0200 Subject: [PATCH] Simplify interface --- eframe/src/web/backend.rs | 7 ++++--- egui_demo_app/src/lib.rs | 17 ++--------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/eframe/src/web/backend.rs b/eframe/src/web/backend.rs index 7849ea72..f231172a 100644 --- a/eframe/src/web/backend.rs +++ b/eframe/src/web/backend.rs @@ -35,7 +35,7 @@ impl WebInput { // ---------------------------------------------------------------------------- -use std::{any::Any, sync::atomic::Ordering::SeqCst}; +use std::sync::atomic::Ordering::SeqCst; /// Stores when to do the next repaint. pub struct NeedRepaint(Mutex); @@ -265,8 +265,9 @@ impl AppRunner { &self.egui_ctx } - pub fn get_app_mut(&mut self) -> &mut dyn Any { - self.app.as_any_mut() + /// Get mutable access to the concrete [`App`] we enclose. + pub fn app_mut(&mut self) -> &mut ConreteApp { + self.app.as_any_mut().downcast_mut::().unwrap() } pub fn auto_save(&mut self) { diff --git a/egui_demo_app/src/lib.rs b/egui_demo_app/src/lib.rs index b00cad8e..aafd53ae 100644 --- a/egui_demo_app/src/lib.rs +++ b/egui_demo_app/src/lib.rs @@ -32,7 +32,6 @@ pub struct WebHandle { #[wasm_bindgen] impl WebHandle { #[wasm_bindgen] - #[cfg(target_arch = "wasm32")] pub fn stop_web(&self) -> Result<(), wasm_bindgen::JsValue> { let mut app = self.handle.lock(); let res = app.destroy(); @@ -44,22 +43,10 @@ impl WebHandle { res } - // helper for mutating original app from javascript - fn with_app(&mut self, func: F) -> () - where - F: Fn(&mut WrapApp) -> (), - { - let mut runner_ref = self.handle.lock(); - let app_ref = runner_ref.get_app_mut(); - let app = app_ref.downcast_mut::().unwrap(); - func(app); - } - #[wasm_bindgen] pub fn set_some_content_from_javasript(&mut self, _some_data: &str) { - self.with_app(|_app| { - // app.data = some_data; - }); + let _app = self.handle.lock().app_mut::(); + // _app.data = some_data; } }