egui: update main to compile with eframe 0.29

These lines are basically copied from eframe_template, as before.
This commit is contained in:
Tomasz Cichoń 2024-10-02 17:30:27 +02:00
parent 4da0c244f3
commit cbe9d8fc1c
1 changed files with 14 additions and 1 deletions

View File

@ -45,15 +45,28 @@ fn main() -> eframe::Result<()> {
// Build to Web. // Build to Web.
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
fn main() { fn main() {
use eframe::wasm_bindgen::JsCast;
// Redirect `log` message to `console.log`: // Redirect `log` message to `console.log`:
eframe::WebLogger::init(log::LevelFilter::Debug).ok(); eframe::WebLogger::init(log::LevelFilter::Debug).ok();
let web_options = eframe::WebOptions::default(); let web_options = eframe::WebOptions::default();
wasm_bindgen_futures::spawn_local(async { wasm_bindgen_futures::spawn_local(async {
let document = eframe::web_sys::window()
.expect("No window")
.document()
.expect("No document");
let canvas = document
.get_element_by_id("topola-egui")
.expect("Failed to find the canvas id")
.dyn_into::<eframe::web_sys::HtmlCanvasElement>()
.expect("topola-egui was not a HtmlCanvasElement");
let start_result = eframe::WebRunner::new() let start_result = eframe::WebRunner::new()
.start( .start(
"topola-egui", canvas,
web_options, web_options,
Box::new(|cc| Ok(Box::new(App::new(cc, langid!("en-US"))))), Box::new(|cc| Ok(Box::new(App::new(cc, langid!("en-US"))))),
) )