Allow to replace an element instead of append to body

This commit is contained in:
traxys 2022-09-19 16:19:15 +02:00 committed by Héctor Ramón Jiménez
parent d222b5c8b0
commit ab2872fe2b
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -159,9 +159,14 @@ where
let document = window.document().unwrap();
let body = document.body().unwrap();
let _ = body
.append_child(&canvas)
.expect("Append canvas to HTML body");
let _ = match body.query_selector("#iced_root").unwrap() {
Some(e) => body
.replace_child(&canvas, &e)
.expect("Could not replace iced_root"),
None => body
.append_child(&canvas)
.expect("Append canvas to HTML body"),
};
}
let (compositor, renderer) = C::new(compositor_settings, Some(&window))?;