Simplify interface

This commit is contained in:
Emil Ernerfeldt 2022-08-20 10:04:12 +02:00
parent d3e26cd00a
commit ba9d1e446c
2 changed files with 6 additions and 18 deletions

View file

@ -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. /// Stores when to do the next repaint.
pub struct NeedRepaint(Mutex<f64>); pub struct NeedRepaint(Mutex<f64>);
@ -265,8 +265,9 @@ impl AppRunner {
&self.egui_ctx &self.egui_ctx
} }
pub fn get_app_mut(&mut self) -> &mut dyn Any { /// Get mutable access to the concrete [`App`] we enclose.
self.app.as_any_mut() pub fn app_mut<ConreteApp: 'static + crate::App>(&mut self) -> &mut ConreteApp {
self.app.as_any_mut().downcast_mut::<ConreteApp>().unwrap()
} }
pub fn auto_save(&mut self) { pub fn auto_save(&mut self) {

View file

@ -32,7 +32,6 @@ pub struct WebHandle {
#[wasm_bindgen] #[wasm_bindgen]
impl WebHandle { impl WebHandle {
#[wasm_bindgen] #[wasm_bindgen]
#[cfg(target_arch = "wasm32")]
pub fn stop_web(&self) -> Result<(), wasm_bindgen::JsValue> { pub fn stop_web(&self) -> Result<(), wasm_bindgen::JsValue> {
let mut app = self.handle.lock(); let mut app = self.handle.lock();
let res = app.destroy(); let res = app.destroy();
@ -44,22 +43,10 @@ impl WebHandle {
res res
} }
// helper for mutating original app from javascript
fn with_app<F>(&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::<WrapApp>().unwrap();
func(app);
}
#[wasm_bindgen] #[wasm_bindgen]
pub fn set_some_content_from_javasript(&mut self, _some_data: &str) { pub fn set_some_content_from_javasript(&mut self, _some_data: &str) {
self.with_app(|_app| { let _app = self.handle.lock().app_mut::<WrapApp>();
// app.data = some_data; // _app.data = some_data;
});
} }
} }