mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Handle for app from WehHandle
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use core::any::Any;
|
||||
|
||||
use eframe::egui_glow;
|
||||
use egui::mutex::Mutex;
|
||||
use egui_glow::glow;
|
||||
@@ -49,6 +52,11 @@ impl eframe::App for Custom3d {
|
||||
self.rotating_triangle.lock().destroy(gl);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
impl Custom3d {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use core::any::Any;
|
||||
|
||||
use eframe::{
|
||||
egui_wgpu::{self, wgpu},
|
||||
wgpu::util::DeviceExt,
|
||||
@@ -117,6 +120,11 @@ impl eframe::App for Custom3d {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
impl Custom3d {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use egui_extras::RetainedImage;
|
||||
use poll_promise::Promise;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use core::any::Any;
|
||||
|
||||
struct Resource {
|
||||
/// HTTP response
|
||||
response: ehttp::Response,
|
||||
@@ -106,6 +109,11 @@ impl eframe::App for HttpApp {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
fn ui_url(ui: &mut egui::Ui, frame: &mut eframe::Frame, url: &mut String) -> bool {
|
||||
|
||||
@@ -43,6 +43,25 @@ 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]
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn set_some_content_from_javasript(&mut self, _some_data: &str) {
|
||||
self.with_app(|_app| {
|
||||
// app.data = some_data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
||||
@@ -3,6 +3,9 @@ use egui_demo_lib::is_mobile;
|
||||
#[cfg(feature = "glow")]
|
||||
use eframe::glow;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use core::any::Any;
|
||||
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
struct EasyMarkApp {
|
||||
@@ -13,6 +16,11 @@ impl eframe::App for EasyMarkApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
self.editor.panels(ctx);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -27,6 +35,11 @@ impl eframe::App for DemoApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
self.demo_windows.ui(ctx);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -46,6 +59,11 @@ impl eframe::App for FractalClockApp {
|
||||
.ui(ui, Some(crate::seconds_since_midnight()));
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -70,6 +88,11 @@ impl eframe::App for ColorTestApp {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -214,6 +237,11 @@ impl eframe::App for WrapApp {
|
||||
fn on_exit(&mut self, gl: Option<&glow::Context>) {
|
||||
self.custom3d.on_exit(gl);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
||||
impl WrapApp {
|
||||
|
||||
Reference in New Issue
Block a user