[egui_web] Simplify the arguments you pass to start()

This commit is contained in:
Emil Ernerfeldt 2020-12-19 21:15:07 +01:00
parent 8f034d391d
commit fb941cf618
4 changed files with 12 additions and 7 deletions

View file

@ -11,8 +11,6 @@ use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
let app = egui::DemoApp::default();
let backend = egui_web::WebBackend::new(canvas_id)?;
let runner = egui_web::AppRunner::new(backend, Box::new(app))?;
egui_web::start(runner)?;
egui_web::start(canvas_id, Box::new(app))?;
Ok(())
}

View file

@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed ⭐
* Set a maximum canvas size to alleviate performance issues on some machines
* Simplify `egui_web::start` arguments
## 0.4.0 - 2020-11-28

View file

@ -221,9 +221,17 @@ impl AppRunner {
}
}
/// Install event listeners to register different input events
/// and starts running the given app.
pub fn start(canvas_id: &str, app: Box<dyn App>) -> Result<AppRunnerRef, JsValue> {
let backend = WebBackend::new(canvas_id)?;
let runner = AppRunner::new(backend, app)?;
start_runner(runner)
}
/// Install event listeners to register different input events
/// and starts running the given `AppRunner`.
pub fn start(app_runner: AppRunner) -> Result<AppRunnerRef, JsValue> {
fn start_runner(app_runner: AppRunner) -> Result<AppRunnerRef, JsValue> {
let runner_ref = AppRunnerRef(Arc::new(Mutex::new(app_runner)));
install_canvas_events(&runner_ref)?;
install_document_events(&runner_ref)?;

View file

@ -13,8 +13,6 @@ use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
let app = example_app::ExampleApp::default();
let backend = egui_web::WebBackend::new(canvas_id)?;
let runner = egui_web::AppRunner::new(backend, Box::new(app))?;
egui_web::start(runner)?;
egui_web::start(canvas_id, Box::new(app))?;
Ok(())
}