mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
refactor RunMode: move it from backend to the demo App (#23)
This simplifies the egui_glium and egui_web backends substantially, reduces the scope of RunMode to a single file, and removes duplicated code. Basically: this is how I should have written it from the beginning.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::*;
|
||||
|
||||
pub use egui::{
|
||||
app::{App, Backend, RunMode, WebInfo},
|
||||
app::{App, Backend, WebInfo},
|
||||
Srgba,
|
||||
};
|
||||
|
||||
@@ -12,12 +12,11 @@ pub struct WebBackend {
|
||||
painter: webgl::Painter,
|
||||
frame_times: egui::MovementTracker<f32>,
|
||||
frame_start: Option<f64>,
|
||||
run_mode: RunMode,
|
||||
last_save_time: Option<f64>,
|
||||
}
|
||||
|
||||
impl WebBackend {
|
||||
pub fn new(canvas_id: &str, run_mode: RunMode) -> Result<Self, JsValue> {
|
||||
pub fn new(canvas_id: &str) -> Result<Self, JsValue> {
|
||||
let ctx = egui::Context::new();
|
||||
load_memory(&ctx);
|
||||
Ok(Self {
|
||||
@@ -25,7 +24,6 @@ impl WebBackend {
|
||||
painter: webgl::Painter::new(canvas_id)?,
|
||||
frame_times: egui::MovementTracker::new(1000, 1.0),
|
||||
frame_start: None,
|
||||
run_mode,
|
||||
last_save_time: None,
|
||||
})
|
||||
}
|
||||
@@ -83,14 +81,6 @@ impl WebBackend {
|
||||
}
|
||||
|
||||
impl Backend for WebBackend {
|
||||
fn run_mode(&self) -> RunMode {
|
||||
self.run_mode
|
||||
}
|
||||
|
||||
fn set_run_mode(&mut self, run_mode: RunMode) {
|
||||
self.run_mode = run_mode;
|
||||
}
|
||||
|
||||
fn web_info(&self) -> Option<WebInfo> {
|
||||
Some(WebInfo {
|
||||
web_location_hash: location_hash().unwrap_or_default(),
|
||||
|
||||
@@ -229,7 +229,7 @@ pub struct AppRunnerRef(Arc<Mutex<AppRunner>>);
|
||||
fn paint_and_schedule(runner_ref: AppRunnerRef) -> Result<(), JsValue> {
|
||||
fn paint_if_needed(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
|
||||
let mut runner_lock = runner_ref.0.lock();
|
||||
if runner_lock.web_backend.run_mode() == RunMode::Continuous || runner_lock.needs_repaint {
|
||||
if runner_lock.needs_repaint {
|
||||
runner_lock.needs_repaint = false;
|
||||
let (output, paint_jobs) = runner_lock.logic()?;
|
||||
runner_lock.paint(paint_jobs)?;
|
||||
|
||||
Reference in New Issue
Block a user