diff options
Diffstat (limited to 'winit/src')
-rw-r--r-- | winit/src/application.rs | 24 | ||||
-rw-r--r-- | winit/src/application/state.rs | 4 | ||||
-rw-r--r-- | winit/src/conversion.rs | 12 | ||||
-rw-r--r-- | winit/src/lib.rs | 2 | ||||
-rw-r--r-- | winit/src/settings.rs | 12 | ||||
-rw-r--r-- | winit/src/settings/macos.rs | 1 | ||||
-rw-r--r-- | winit/src/settings/wasm.rs | 11 | ||||
-rw-r--r-- | winit/src/settings/windows.rs | 1 |
8 files changed, 49 insertions, 18 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))?; 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()); } } 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<winit::window::Fullscreen>) -> 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( 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<Flags> { /// communicate with it through the windowing system. pub id: Option<String>, - /// 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<String>, +} 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. |