Simplify interface
This commit is contained in:
parent
d3e26cd00a
commit
ba9d1e446c
2 changed files with 6 additions and 18 deletions
|
@ -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<f64>);
|
||||
|
@ -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<ConreteApp: 'static + crate::App>(&mut self) -> &mut ConreteApp {
|
||||
self.app.as_any_mut().downcast_mut::<ConreteApp>().unwrap()
|
||||
}
|
||||
|
||||
pub fn auto_save(&mut self) {
|
||||
|
|
|
@ -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<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]
|
||||
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::<WrapApp>();
|
||||
// _app.data = some_data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue