diff --git a/demo/src/main.rs b/demo/src/main.rs index 74d9aa6..f2b0735 100644 --- a/demo/src/main.rs +++ b/demo/src/main.rs @@ -27,25 +27,35 @@ fn main() -> eframe::Result { // When compiling to web using trunk: #[cfg(target_arch = "wasm32")] fn main() { + use eframe::wasm_bindgen::JsCast as _; + // Redirect `log` message to `console.log` and friends: eframe::WebLogger::init(log::LevelFilter::Debug).ok(); let web_options = eframe::WebOptions::default(); wasm_bindgen_futures::spawn_local(async { + let document = web_sys::window() + .expect("No window") + .document() + .expect("No document"); + + let canvas = document + .get_element_by_id("the_canvas_id") + .expect("Faield to find the_canvas_id") + .dyn_into::() + .expect("the_canvas_id was not a HtmlCanvasElement"); + let start_result = eframe::WebRunner::new() .start( - "the_canvas_id", + canvas, web_options, Box::new(|cc| Ok(Box::new(demo::TemplateApp::new(cc)))), ) .await; // Remove the loading text and spinner: - let loading_text = web_sys::window() - .and_then(|w| w.document()) - .and_then(|d| d.get_element_by_id("loading_text")); - if let Some(loading_text) = loading_text { + if let Some(loading_text) = document.get_element_by_id("loading_text") { match start_result { Ok(_) => { loading_text.remove();