From 7ea7dbef578ddbe2a9a50da6aab253ba016f1362 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Thu, 6 Oct 2022 20:38:21 +0200 Subject: feat: Add window drag support from winit Exposes access to the winit window's window_drag method as an action. --- winit/src/application.rs | 3 +++ winit/src/window.rs | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'winit') diff --git a/winit/src/application.rs b/winit/src/application.rs index 0496aea9..75c113bf 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -615,6 +615,9 @@ pub fn run_command( } }, 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, diff --git a/winit/src/window.rs b/winit/src/window.rs index 265139f7..61c9c3fe 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -4,6 +4,11 @@ use iced_native::window; pub use window::{Event, Mode}; +/// Begins dragging the window while the left mouse button is held. +pub fn drag() -> Command { + Command::single(command::Action::Window(window::Action::Drag)) +} + /// Resizes the window to the given logical dimensions. pub fn resize(width: u32, height: u32) -> Command { Command::single(command::Action::Window(window::Action::Resize { -- cgit From 8a50836ffc32a6d9157eb18740b3947c4dbd7d1f Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Sun, 9 Oct 2022 16:35:28 +0200 Subject: feat: Add window maximize support --- winit/src/application.rs | 6 ++++++ winit/src/window.rs | 10 ++++++++++ 2 files changed, 16 insertions(+) (limited to 'winit') diff --git a/winit/src/application.rs b/winit/src/application.rs index 75c113bf..7de5a0ce 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -624,6 +624,9 @@ pub fn run_command( height, }); } + window::Action::Maximize(value) => { + window.set_maximized(value); + } window::Action::Move { x, y } => { window.set_outer_position(winit::dpi::LogicalPosition { x, @@ -637,6 +640,9 @@ pub fn run_command( 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()) diff --git a/winit/src/window.rs b/winit/src/window.rs index 61c9c3fe..48210c33 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -17,6 +17,11 @@ pub fn resize(width: u32, height: u32) -> Command { })) } +/// Sets the window to maximized or back. +pub fn maximize(value: bool) -> Command { + Command::single(command::Action::Window(window::Action::Maximize(value))) +} + /// Moves a window to the given logical coordinates. pub fn move_to(x: i32, y: i32) -> Command { Command::single(command::Action::Window(window::Action::Move { x, y })) @@ -27,6 +32,11 @@ pub fn set_mode(mode: Mode) -> Command { Command::single(command::Action::Window(window::Action::SetMode(mode))) } +/// Sets the window to maximized or back. +pub fn toggle_maximize() -> Command { + Command::single(command::Action::Window(window::Action::ToggleMaximize)) +} + /// Fetches the current [`Mode`] of the window. pub fn fetch_mode( f: impl FnOnce(Mode) -> Message + 'static, -- cgit From ac6e137be3e9d2d2a1d8c1284880096a0e2c2a47 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 11 Oct 2022 15:24:26 +0200 Subject: feat: Add window minimize support --- winit/src/application.rs | 3 +++ winit/src/window.rs | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'winit') diff --git a/winit/src/application.rs b/winit/src/application.rs index 7de5a0ce..939a50c9 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -627,6 +627,9 @@ pub fn run_command( 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, diff --git a/winit/src/window.rs b/winit/src/window.rs index 48210c33..1e704c5b 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -22,6 +22,11 @@ pub fn maximize(value: bool) -> Command { Command::single(command::Action::Window(window::Action::Maximize(value))) } +/// Set the window to minimized or back. +pub fn minimize(value: bool) -> Command { + Command::single(command::Action::Window(window::Action::Minimize(value))) +} + /// Moves a window to the given logical coordinates. pub fn move_to(x: i32, y: i32) -> Command { Command::single(command::Action::Window(window::Action::Move { x, y })) -- cgit 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') 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') 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') 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') 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 b0e8bafb6c51666e8b15531001263097ae7d7c0e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 01:20:11 +0100 Subject: Bump versions :tada: --- winit/Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'winit') diff --git a/winit/Cargo.toml b/winit/Cargo.toml index d3ed949f..1133adb1 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_winit" -version = "0.4.0" +version = "0.5.0" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A winit runtime for Iced" @@ -26,15 +26,15 @@ git = "https://github.com/iced-rs/winit.git" rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c" [dependencies.iced_native] -version = "0.5" +version = "0.6" path = "../native" [dependencies.iced_graphics] -version = "0.3" +version = "0.4" path = "../graphics" [dependencies.iced_futures] -version = "0.4" +version = "0.5" path = "../futures" [target.'cfg(target_os = "windows")'.dependencies.winapi] -- 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') 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 From 23299a555f8b7e908a6a14915307792a7cf97b9a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 18:15:10 +0100 Subject: Bump versions :tada: --- winit/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit') diff --git a/winit/Cargo.toml b/winit/Cargo.toml index 1133adb1..a3ac3ddd 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_winit" -version = "0.5.0" +version = "0.5.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A winit runtime for Iced" -- cgit From 4c61f12768cdbe728b1dd4a074e36fb6a69534ab Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 7 Dec 2022 04:38:00 +0100 Subject: Bump versions :tada: --- winit/Cargo.toml | 6 +++--- winit/src/conversion.rs | 12 ++++++------ winit/src/lib.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'winit') diff --git a/winit/Cargo.toml b/winit/Cargo.toml index a3ac3ddd..ebbadb12 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_winit" -version = "0.5.1" +version = "0.6.0" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A winit runtime for Iced" @@ -26,11 +26,11 @@ git = "https://github.com/iced-rs/winit.git" rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c" [dependencies.iced_native] -version = "0.6" +version = "0.7" path = "../native" [dependencies.iced_graphics] -version = "0.4" +version = "0.5" path = "../graphics" [dependencies.iced_futures] diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 0707aed5..b1076afe 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.5/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/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.5/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/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.5/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/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.5/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/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.5/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/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.5/native +/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/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 bb3a3d5b..b8ed492d 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.5/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native //! [`winit`]: https://github.com/rust-windowing/winit //! [`conversion`]: crate::conversion #![doc( -- cgit