1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 23:13:13 -04:00

Handle for app from WehHandle

This commit is contained in:
Stanislav
2022-08-03 19:27:19 +03:00
parent a827c3e033
commit fd9c8e5e08
8 changed files with 93 additions and 1 deletions

View File

@@ -6,6 +6,9 @@
#![warn(missing_docs)] // Let's keep `epi` well-documented.
#[cfg(target_arch = "wasm32")]
use std::any::Any;
/// This is how your app is created.
///
/// You can use the [`CreationContext`] to setup egui, restore state, setup OpenGL things, etc.
@@ -49,6 +52,15 @@ pub trait App {
/// To force a repaint, call [`egui::Context::request_repaint`] at any time (e.g. from another thread).
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame);
// Handle to the app.
//
// Can be used from web to interact or other external context
// Implementation is needed, because downcasting Box<dyn App> -> Box<dyn Any> to get &ConcreteApp is not simple in current rust.
//
// Just return &mut *self
#[cfg(target_arch = "wasm32")]
fn as_any_mut(&mut self) -> &mut dyn Any;
/// Called on shutdown, and perhaps at regular intervals. Allows you to save state.
///
/// Only called when the "persistence" feature is enabled.

View File

@@ -35,7 +35,7 @@ impl WebInput {
// ----------------------------------------------------------------------------
use std::sync::atomic::Ordering::SeqCst;
use std::{any::Any, sync::atomic::Ordering::SeqCst};
/// Stores when to do the next repaint.
pub struct NeedRepaint(Mutex<f64>);
@@ -265,6 +265,10 @@ impl AppRunner {
&self.egui_ctx
}
pub fn get_app_mut(&mut self) -> &mut dyn Any {
self.app.as_any_mut()
}
pub fn auto_save(&mut self) {
let now = now_sec();
let time_since_last_save = now - self.last_save_time;