diff options
Diffstat (limited to 'winit/src/application.rs')
-rw-r--r-- | winit/src/application.rs | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index 0496aea9..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))?; @@ -615,12 +629,21 @@ pub fn run_command<A, E>( } }, command::Action::Window(action) => match action { + window::Action::Drag => { + let _res = window.drag_window(); + } window::Action::Resize { width, height } => { window.set_inner_size(winit::dpi::LogicalSize { width, height, }); } + window::Action::Maximize(value) => { + window.set_maximized(value); + } + window::Action::Minimize(value) => { + window.set_minimized(value); + } window::Action::Move { x, y } => { window.set_outer_position(winit::dpi::LogicalPosition { x, @@ -634,6 +657,9 @@ pub fn run_command<A, E>( mode, )); } + window::Action::ToggleMaximize => { + window.set_maximized(!window.is_maximized()) + } window::Action::FetchMode(tag) => { let mode = if window.is_visible().unwrap_or(true) { conversion::mode(window.fullscreen()) |