Allow providing a DOM identifier as a target for Wasm
This commit is contained in:
parent
ab2872fe2b
commit
d8d57a800a
5 changed files with 34 additions and 8 deletions
|
|
@ -137,6 +137,9 @@ where
|
|||
runtime.enter(|| A::new(flags))
|
||||
};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let target = settings.window.platform_specific.target.clone();
|
||||
|
||||
let builder = settings.window.into_builder(
|
||||
&application.title(),
|
||||
event_loop.primary_monitor(),
|
||||
|
|
@ -159,10 +162,16 @@ where
|
|||
let document = window.document().unwrap();
|
||||
let body = document.body().unwrap();
|
||||
|
||||
let _ = match body.query_selector("#iced_root").unwrap() {
|
||||
Some(e) => body
|
||||
.replace_child(&canvas, &e)
|
||||
.expect("Could not replace iced_root"),
|
||||
let target = target.and_then(|target| {
|
||||
body.query_selector(&format!("#{}", target))
|
||||
.ok()
|
||||
.unwrap_or(None)
|
||||
});
|
||||
|
||||
let _ = match target {
|
||||
Some(node) => node
|
||||
.replace_child(&canvas, &node)
|
||||
.expect(&format!("Could not replace #{}", node.id())),
|
||||
None => body
|
||||
.append_child(&canvas)
|
||||
.expect("Append canvas to HTML body"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue