summaryrefslogtreecommitdiffstats
path: root/winit/src/application.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-02 18:53:21 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-02 18:53:21 +0100
commit4029a1cdaaac1abbdcc141b20469a49670cd99b6 (patch)
tree71fa9d9c4aa1f02ce05771db43a4bb7bc6570e77 /winit/src/application.rs
parent676d8efe03ebdbeeb95aef96b8097395b788b1ab (diff)
parent8b55e9b9e6ba0b83038dd491dd34d95b4f9a381b (diff)
downloadiced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.tar.gz
iced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.tar.bz2
iced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.zip
Merge branch 'master' into non-uniform-border-radius-for-quads
Diffstat (limited to '')
-rw-r--r--winit/src/application.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 939a50c9..1706d2e9 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -58,10 +58,10 @@ where
/// title of your application when necessary.
fn title(&self) -> String;
- /// Returns the current [`Theme`] of the [`Application`].
+ /// Returns the current `Theme` of the [`Application`].
fn theme(&self) -> <Self::Renderer as crate::Renderer>::Theme;
- /// Returns the [`Style`] variation of the [`Theme`].
+ /// Returns the `Style` variation of the `Theme`.
fn style(
&self,
) -> <<Self::Renderer as crate::Renderer>::Theme as StyleSheet>::Style {
@@ -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,9 +162,20 @@ where
let document = window.document().unwrap();
let body = document.body().unwrap();
- let _ = body
- .append_child(&canvas)
- .expect("Append canvas to HTML body");
+ 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"),
+ };
}
let (compositor, renderer) = C::new(compositor_settings, Some(&window))?;