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. --- native/src/window/action.rs | 8 ++++++++ winit/src/application.rs | 3 +++ winit/src/window.rs | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/native/src/window/action.rs b/native/src/window/action.rs index 73338e22..ce125144 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -5,6 +5,12 @@ use std::fmt; /// An operation to be performed on some window. pub enum Action { + /// Moves the window with the left mouse button until the button is + /// released. + /// + /// There’s no guarantee that this will work unless the left mouse + /// button was pressed immediately before this function is called. + Drag, /// Resize the window. Resize { /// The new logical width of the window @@ -37,6 +43,7 @@ impl Action { T: 'static, { match self { + Self::Drag => Action::Drag, Self::Resize { width, height } => Action::Resize { width, height }, Self::Move { x, y } => Action::Move { x, y }, Self::SetMode(mode) => Action::SetMode(mode), @@ -48,6 +55,7 @@ impl Action { impl fmt::Debug for Action { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { + Self::Drag => write!(f, "Action::Drag"), Self::Resize { width, height } => write!( f, "Action::Resize {{ widget: {}, height: {} }}", 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 --- native/src/window/action.rs | 8 ++++++++ winit/src/application.rs | 6 ++++++ winit/src/window.rs | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/native/src/window/action.rs b/native/src/window/action.rs index ce125144..c49fdf9d 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -18,6 +18,8 @@ pub enum Action { /// The new logical height of the window height: u32, }, + /// Sets the window to maximized or back + Maximize(bool), /// Move the window. /// /// Unsupported on Wayland. @@ -29,6 +31,8 @@ pub enum Action { }, /// Set the [`Mode`] of the window. SetMode(Mode), + /// Sets the window to maximized or back + ToggleMaximize, /// Fetch the current [`Mode`] of the window. FetchMode(Box T + 'static>), } @@ -45,8 +49,10 @@ impl Action { match self { Self::Drag => Action::Drag, Self::Resize { width, height } => Action::Resize { width, height }, + Self::Maximize(bool) => Action::Maximize(bool), Self::Move { x, y } => Action::Move { x, y }, Self::SetMode(mode) => Action::SetMode(mode), + Self::ToggleMaximize => Action::ToggleMaximize, Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))), } } @@ -61,10 +67,12 @@ impl fmt::Debug for Action { "Action::Resize {{ widget: {}, height: {} }}", width, height ), + Self::Maximize(value) => write!(f, "Action::Maximize({})", value), Self::Move { x, y } => { write!(f, "Action::Move {{ x: {}, y: {} }}", x, y) } Self::SetMode(mode) => write!(f, "Action::SetMode({:?})", mode), + Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"), Self::FetchMode(_) => write!(f, "Action::FetchMode"), } } 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 --- native/src/window/action.rs | 4 ++++ winit/src/application.rs | 3 +++ winit/src/window.rs | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/native/src/window/action.rs b/native/src/window/action.rs index c49fdf9d..009dcc27 100644 --- a/native/src/window/action.rs +++ b/native/src/window/action.rs @@ -20,6 +20,8 @@ pub enum Action { }, /// Sets the window to maximized or back Maximize(bool), + /// Set the window to minimized or back + Minimize(bool), /// Move the window. /// /// Unsupported on Wayland. @@ -50,6 +52,7 @@ impl Action { Self::Drag => Action::Drag, Self::Resize { width, height } => Action::Resize { width, height }, Self::Maximize(bool) => Action::Maximize(bool), + Self::Minimize(bool) => Action::Minimize(bool), Self::Move { x, y } => Action::Move { x, y }, Self::SetMode(mode) => Action::SetMode(mode), Self::ToggleMaximize => Action::ToggleMaximize, @@ -68,6 +71,7 @@ impl fmt::Debug for Action { width, height ), Self::Maximize(value) => write!(f, "Action::Maximize({})", value), + Self::Minimize(value) => write!(f, "Action::Minimize({}", value), Self::Move { x, y } => { write!(f, "Action::Move {{ x: {}, y: {} }}", x, y) } 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