Append Canvas to <body> when targetting Wasm in iced_winit

This commit is contained in:
Héctor Ramón Jiménez 2022-01-28 16:55:16 +07:00
parent 825c7749ff
commit 26d95fdc4b
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 19 additions and 0 deletions

View file

@ -37,3 +37,7 @@ path = "../futures"
[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.6"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3"
features = ["Document", "Window"]

View file

@ -148,6 +148,21 @@ where
.build(&event_loop)
.map_err(Error::WindowCreationFailed)?;
#[cfg(target_arch = "wasm32")]
{
use winit::platform::web::WindowExtWebSys;
let canvas = window.canvas();
let window = web_sys::window().unwrap();
let document = window.document().unwrap();
let body = document.body().unwrap();
let _ = body
.append_child(&canvas)
.expect("Append canvas to HTML body");
}
let mut clipboard = Clipboard::connect(&window);
run_command(