From ab2872fe2be5b694f65125b86e5c03b1f3506ac3 Mon Sep 17 00:00:00 2001 From: traxys Date: Mon, 19 Sep 2022 16:19:15 +0200 Subject: Allow to replace an element instead of append to body --- winit/src/application.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 939a50c9..db0ab938 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -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))?; -- cgit From d8d57a800a2e1bd11dc4d69634d630c8e6117c39 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 5 Nov 2022 01:43:28 +0100 Subject: Allow providing a DOM identifier as a `target` for Wasm --- winit/src/application.rs | 17 +++++++++++++---- winit/src/settings.rs | 12 ++++++++++-- winit/src/settings/macos.rs | 1 - winit/src/settings/wasm.rs | 11 +++++++++++ winit/src/settings/windows.rs | 1 - 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 winit/src/settings/wasm.rs (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index db0ab938..ffaaa8fb 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -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"), diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 6387454b..9bbdef5c 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -7,7 +7,15 @@ mod platform; #[path = "settings/macos.rs"] mod platform; -#[cfg(not(any(target_os = "windows", target_os = "macos")))] +#[cfg(target_arch = "wasm32")] +#[path = "settings/wasm.rs"] +mod platform; + +#[cfg(not(any( + target_os = "windows", + target_os = "macos", + target_arch = "wasm32" +)))] #[path = "settings/other.rs"] mod platform; @@ -27,7 +35,7 @@ pub struct Settings { /// communicate with it through the windowing system. pub id: Option, - /// The [`Window`] settings + /// The [`Window`] settings. pub window: Window, /// The data needed to initialize an [`Application`]. diff --git a/winit/src/settings/macos.rs b/winit/src/settings/macos.rs index ad4c8cae..f86e63ad 100644 --- a/winit/src/settings/macos.rs +++ b/winit/src/settings/macos.rs @@ -1,4 +1,3 @@ -#![cfg(target_os = "macos")] //! Platform specific settings for macOS. /// The platform specific window settings of an application. diff --git a/winit/src/settings/wasm.rs b/winit/src/settings/wasm.rs new file mode 100644 index 00000000..8e0f1bbc --- /dev/null +++ b/winit/src/settings/wasm.rs @@ -0,0 +1,11 @@ +//! Platform specific settings for WebAssembly. + +/// The platform specific window settings of an application. +#[derive(Debug, Clone, PartialEq, Eq, Default)] +pub struct PlatformSpecific { + /// The identifier of a DOM element that will be replaced with the + /// application. + /// + /// If set to `None`, the application will be appended to the HTML body. + pub target: Option, +} diff --git a/winit/src/settings/windows.rs b/winit/src/settings/windows.rs index 9bef1eaf..ff03a9c5 100644 --- a/winit/src/settings/windows.rs +++ b/winit/src/settings/windows.rs @@ -1,4 +1,3 @@ -#![cfg(target_os = "windows")] //! Platform specific settings for Windows. /// The platform specific window settings of an application. -- cgit From 18fb74f20092b2703a90afdb01f39754445998da Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 9 Nov 2022 04:05:31 +0100 Subject: Introduce `Custom` variants for every style in the built-in `Theme` --- winit/src/application/state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index 9c539548..8d6a1df1 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -32,7 +32,7 @@ where let title = application.title(); let scale_factor = application.scale_factor(); let theme = application.theme(); - let appearance = theme.appearance(application.style()); + let appearance = theme.appearance(&application.style()); let viewport = { let physical_size = window.inner_size(); @@ -210,6 +210,6 @@ where // Update theme and appearance self.theme = application.theme(); - self.appearance = self.theme.appearance(application.style()); + self.appearance = self.theme.appearance(&application.style()); } } -- cgit From 1480ab20306e463b69b2229dcd5e81d4c66b2a64 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 00:10:53 +0100 Subject: Fix broken documentation links --- winit/src/application.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index ffaaa8fb..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) -> ::Theme; - /// Returns the [`Style`] variation of the [`Theme`]. + /// Returns the `Style` variation of the `Theme`. fn style( &self, ) -> <::Theme as StyleSheet>::Style { -- cgit From a6298ba12c038d5eaddca9327abb385aa72a82e9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 18:14:40 +0100 Subject: Fix outdated links in documentation --- winit/src/conversion.rs | 12 ++++++------ winit/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'winit/src') diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index ba5b0002..0707aed5 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -1,7 +1,7 @@ //! Convert [`winit`] types into [`iced_native`] types, and viceversa. //! //! [`winit`]: https://github.com/rust-windowing/winit -//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native use crate::keyboard; use crate::mouse; use crate::touch; @@ -218,7 +218,7 @@ pub fn mode(mode: Option) -> window::Mode { /// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native pub fn mouse_interaction( interaction: mouse::Interaction, ) -> winit::window::CursorIcon { @@ -242,7 +242,7 @@ pub fn mouse_interaction( /// Converts a `MouseButton` from [`winit`] to an [`iced_native`] mouse button. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button { match mouse_button { winit::event::MouseButton::Left => mouse::Button::Left, @@ -258,7 +258,7 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button { /// modifiers state. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native pub fn modifiers( modifiers: winit::event::ModifiersState, ) -> keyboard::Modifiers { @@ -285,7 +285,7 @@ pub fn cursor_position( /// Converts a `Touch` from [`winit`] to an [`iced_native`] touch event. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native pub fn touch_event( touch: winit::event::Touch, scale_factor: f64, @@ -316,7 +316,7 @@ pub fn touch_event( /// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code. /// /// [`winit`]: https://github.com/rust-windowing/winit -/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native pub fn key_code( virtual_keycode: winit::event::VirtualKeyCode, ) -> keyboard::KeyCode { diff --git a/winit/src/lib.rs b/winit/src/lib.rs index edba887b..bb3a3d5b 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -11,7 +11,7 @@ //! Additionally, a [`conversion`] module is available for users that decide to //! implement a custom event loop. //! -//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native //! [`winit`]: https://github.com/rust-windowing/winit //! [`conversion`]: crate::conversion #![doc( -- cgit