Append Canvas to <body> when targetting Wasm in iced_winit
This commit is contained in:
parent
825c7749ff
commit
26d95fdc4b
2 changed files with 19 additions and 0 deletions
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue