From 2aa2b1712dfdc93762ebe0958614154920068731 Mon Sep 17 00:00:00 2001 From: Calastrophe Date: Tue, 9 Jan 2024 02:37:45 -0600 Subject: Implemented fetch_maximized and fetch_minimized --- runtime/src/window.rs | 22 ++++++++++++++++++++++ runtime/src/window/action.rs | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) (limited to 'runtime/src') diff --git a/runtime/src/window.rs b/runtime/src/window.rs index f9d943f6..2136d64d 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -65,11 +65,33 @@ pub fn fetch_size( Command::single(command::Action::Window(Action::FetchSize(id, Box::new(f)))) } +/// Fetches if the window is maximized. +pub fn fetch_maximized( + id: Id, + f: impl FnOnce(bool) -> Message + 'static, +) -> Command { + Command::single(command::Action::Window(Action::FetchMaximized( + id, + Box::new(f), + ))) +} + /// Maximizes the window. pub fn maximize(id: Id, maximized: bool) -> Command { Command::single(command::Action::Window(Action::Maximize(id, maximized))) } +/// Fetches if the window is minimized. +pub fn fetch_minimized( + id: Id, + f: impl FnOnce(Option) -> Message + 'static, +) -> Command { + Command::single(command::Action::Window(Action::FetchMinimized( + id, + Box::new(f), + ))) +} + /// Minimizes the window. pub fn minimize(id: Id, minimized: bool) -> Command { Command::single(command::Action::Window(Action::Minimize(id, minimized))) diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 2d98b607..8b532569 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -21,8 +21,19 @@ pub enum Action { Resize(Id, Size), /// Fetch the current logical dimensions of the window. FetchSize(Id, Box T + 'static>), + /// Fetch if the current window is maximized or not. + /// + /// ## Platform-specific + /// - **iOS / Android / Web:** Unsupported. + FetchMaximized(Id, Box T + 'static>), /// Set the window to maximized or back Maximize(Id, bool), + /// Fetch if the current window is minimized or not. + /// + /// ## Platform-specific + /// - **Wayland:** Always `None`. + /// - **iOS / Android / Web:** Unsupported. + FetchMinimized(Id, Box) -> T + 'static>), /// Set the window to minimized or back Minimize(Id, bool), /// Move the window to the given logical coordinates. @@ -106,7 +117,13 @@ impl Action { Self::FetchSize(id, o) => { Action::FetchSize(id, Box::new(move |s| f(o(s)))) } + Self::FetchMaximized(id, o) => { + Action::FetchMaximized(id, Box::new(move |s| f(o(s)))) + } Self::Maximize(id, maximized) => Action::Maximize(id, maximized), + Self::FetchMinimized(id, o) => { + Action::FetchMinimized(id, Box::new(move |s| f(o(s)))) + } Self::Minimize(id, minimized) => Action::Minimize(id, minimized), Self::Move(id, position) => Action::Move(id, position), Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode), @@ -144,9 +161,15 @@ impl fmt::Debug for Action { write!(f, "Action::Resize({id:?}, {size:?})") } Self::FetchSize(id, _) => write!(f, "Action::FetchSize({id:?})"), + Self::FetchMaximized(id, _) => { + write!(f, "Action::FetchMaximized({id:?})") + } Self::Maximize(id, maximized) => { write!(f, "Action::Maximize({id:?}, {maximized})") } + Self::FetchMinimized(id, _) => { + write!(f, "Action::FetchMinimized({id:?})") + } Self::Minimize(id, minimized) => { write!(f, "Action::Minimize({id:?}, {minimized}") } -- cgit