diff options
| author | 2024-06-20 01:13:09 +0200 | |
|---|---|---|
| committer | 2024-06-20 01:13:09 +0200 | |
| commit | 92e08c8f07511cc212cbce545fb7739ef1a4bf1f (patch) | |
| tree | 9b8a1e7746b13148168109bdbcfc8f94b84c252a | |
| parent | bdd30f7ab8c2280c368b86cb12baec0578669d44 (diff) | |
| download | iced-92e08c8f07511cc212cbce545fb7739ef1a4bf1f.tar.gz iced-92e08c8f07511cc212cbce545fb7739ef1a4bf1f.tar.bz2 iced-92e08c8f07511cc212cbce545fb7739ef1a4bf1f.zip | |
Add `get_latest` and `get_oldest` tasks in `window`
| -rw-r--r-- | runtime/src/window.rs | 76 | ||||
| -rw-r--r-- | winit/src/program.rs | 24 | 
2 files changed, 64 insertions, 36 deletions
| diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 956a20e1..b04e5d59 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -26,6 +26,12 @@ pub enum Action {      /// Close the window and exits the application.      Close(Id), +    /// Gets the [`Id`] of the oldest window. +    GetOldest(oneshot::Sender<Option<Id>>), + +    /// Gets the [`Id`] of the latest window. +    GetLatest(oneshot::Sender<Option<Id>>), +      /// Move the window with the left mouse button until the button is      /// released.      /// @@ -36,26 +42,26 @@ pub enum Action {      /// Resize the window to the given logical dimensions.      Resize(Id, Size), -    /// Fetch the current logical dimensions of the window. -    FetchSize(Id, oneshot::Sender<Size>), +    /// Get the current logical dimensions of the window. +    GetSize(Id, oneshot::Sender<Size>), -    /// Fetch if the current window is maximized or not. -    FetchMaximized(Id, oneshot::Sender<bool>), +    /// Get if the current window is maximized or not. +    GetMaximized(Id, oneshot::Sender<bool>),      /// Set the window to maximized or back      Maximize(Id, bool), -    /// Fetch if the current window is minimized or not. +    /// Get if the current window is minimized or not.      ///      /// ## Platform-specific      /// - **Wayland:** Always `None`. -    FetchMinimized(Id, oneshot::Sender<Option<bool>>), +    GetMinimized(Id, oneshot::Sender<Option<bool>>),      /// Set the window to minimized or back      Minimize(Id, bool), -    /// Fetch the current logical coordinates of the window. -    FetchPosition(Id, oneshot::Sender<Option<Point>>), +    /// Get the current logical coordinates of the window. +    GetPosition(Id, oneshot::Sender<Option<Point>>),      /// Move the window to the given logical coordinates.      /// @@ -65,8 +71,8 @@ pub enum Action {      /// Change the [`Mode`] of the window.      ChangeMode(Id, Mode), -    /// Fetch the current [`Mode`] of the window. -    FetchMode(Id, oneshot::Sender<Mode>), +    /// Get the current [`Mode`] of the window. +    GetMode(Id, oneshot::Sender<Mode>),      /// Toggle the window to maximized or back      ToggleMaximize(Id), @@ -114,8 +120,8 @@ pub enum Action {      /// Android / iOS / macOS / Orbital / Web / X11: Unsupported.      ShowSystemMenu(Id), -    /// Fetch the raw identifier unique to the window. -    FetchRawId(Id, oneshot::Sender<u64>), +    /// Get the raw identifier unique to the window. +    GetRawId(Id, oneshot::Sender<u64>),      /// Change the window [`Icon`].      /// @@ -214,6 +220,16 @@ pub fn close<T>(id: Id) -> Task<T> {      Task::effect(crate::Action::Window(Action::Close(id)))  } +/// Gets the window [`Id`] of the oldest window. +pub fn get_oldest() -> Task<Option<Id>> { +    Task::oneshot(|channel| crate::Action::Window(Action::GetOldest(channel))) +} + +/// Gets the window [`Id`] of the latest window. +pub fn get_latest() -> Task<Option<Id>> { +    Task::oneshot(|channel| crate::Action::Window(Action::GetLatest(channel))) +} +  /// Begins dragging the window while the left mouse button is held.  pub fn drag<T>(id: Id) -> Task<T> {      Task::effect(crate::Action::Window(Action::Drag(id))) @@ -224,17 +240,17 @@ pub fn resize<T>(id: Id, new_size: Size) -> Task<T> {      Task::effect(crate::Action::Window(Action::Resize(id, new_size)))  } -/// Fetches the window's size in logical dimensions. -pub fn fetch_size(id: Id) -> Task<Size> { +/// Get the window's size in logical dimensions. +pub fn get_size(id: Id) -> Task<Size> {      Task::oneshot(move |channel| { -        crate::Action::Window(Action::FetchSize(id, channel)) +        crate::Action::Window(Action::GetSize(id, channel))      })  } -/// Fetches if the window is maximized. -pub fn fetch_maximized(id: Id) -> Task<bool> { +/// Gets the maximized state of the window with the given [`Id`]. +pub fn get_maximized(id: Id) -> Task<bool> {      Task::oneshot(move |channel| { -        crate::Action::Window(Action::FetchMaximized(id, channel)) +        crate::Action::Window(Action::GetMaximized(id, channel))      })  } @@ -243,10 +259,10 @@ pub fn maximize<T>(id: Id, maximized: bool) -> Task<T> {      Task::effect(crate::Action::Window(Action::Maximize(id, maximized)))  } -/// Fetches if the window is minimized. -pub fn fetch_minimized(id: Id) -> Task<Option<bool>> { +/// Gets the minimized state of the window with the given [`Id`]. +pub fn get_minimized(id: Id) -> Task<Option<bool>> {      Task::oneshot(move |channel| { -        crate::Action::Window(Action::FetchMinimized(id, channel)) +        crate::Action::Window(Action::GetMinimized(id, channel))      })  } @@ -255,10 +271,10 @@ pub fn minimize<T>(id: Id, minimized: bool) -> Task<T> {      Task::effect(crate::Action::Window(Action::Minimize(id, minimized)))  } -/// Fetches the current window position in logical coordinates. -pub fn fetch_position(id: Id) -> Task<Option<Point>> { +/// Gets the position in logical coordinates of the window with the given [`Id`]. +pub fn get_position(id: Id) -> Task<Option<Point>> {      Task::oneshot(move |channel| { -        crate::Action::Window(Action::FetchPosition(id, channel)) +        crate::Action::Window(Action::GetPosition(id, channel))      })  } @@ -272,10 +288,10 @@ pub fn change_mode<T>(id: Id, mode: Mode) -> Task<T> {      Task::effect(crate::Action::Window(Action::ChangeMode(id, mode)))  } -/// Fetches the current [`Mode`] of the window. -pub fn fetch_mode(id: Id) -> Task<Mode> { +/// Gets the current [`Mode`] of the window. +pub fn get_mode(id: Id) -> Task<Mode> {      Task::oneshot(move |channel| { -        crate::Action::Window(Action::FetchMode(id, channel)) +        crate::Action::Window(Action::GetMode(id, channel))      })  } @@ -327,11 +343,11 @@ pub fn show_system_menu<T>(id: Id) -> Task<T> {      Task::effect(crate::Action::Window(Action::ShowSystemMenu(id)))  } -/// Fetches an identifier unique to the window, provided by the underlying windowing system. This is +/// Gets an identifier unique to the window, provided by the underlying windowing system. This is  /// not to be confused with [`Id`]. -pub fn fetch_raw_id<Message>(id: Id) -> Task<u64> { +pub fn get_raw_id<Message>(id: Id) -> Task<u64> {      Task::oneshot(|channel| { -        crate::Action::Window(Action::FetchRawId(id, channel)) +        crate::Action::Window(Action::GetRawId(id, channel))      })  } diff --git a/winit/src/program.rs b/winit/src/program.rs index 62f8b6af..2e7945ac 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -1165,6 +1165,18 @@ fn run_action<P, C>(                  let _ = window_manager.remove(id);                  let _ = ui_caches.remove(&id);              } +            window::Action::GetOldest(channel) => { +                let id = +                    window_manager.iter_mut().next().map(|(id, _window)| id); + +                let _ = channel.send(id); +            } +            window::Action::GetLatest(channel) => { +                let id = +                    window_manager.iter_mut().last().map(|(id, _window)| id); + +                let _ = channel.send(id); +            }              window::Action::Drag(id) => {                  if let Some(window) = window_manager.get_mut(id) {                      let _ = window.raw.drag_window(); @@ -1180,7 +1192,7 @@ fn run_action<P, C>(                      );                  }              } -            window::Action::FetchSize(id, channel) => { +            window::Action::GetSize(id, channel) => {                  if let Some(window) = window_manager.get_mut(id) {                      let size = window                          .raw @@ -1190,7 +1202,7 @@ fn run_action<P, C>(                      let _ = channel.send(Size::new(size.width, size.height));                  }              } -            window::Action::FetchMaximized(id, channel) => { +            window::Action::GetMaximized(id, channel) => {                  if let Some(window) = window_manager.get_mut(id) {                      let _ = channel.send(window.raw.is_maximized());                  } @@ -1200,7 +1212,7 @@ fn run_action<P, C>(                      window.raw.set_maximized(maximized);                  }              } -            window::Action::FetchMinimized(id, channel) => { +            window::Action::GetMinimized(id, channel) => {                  if let Some(window) = window_manager.get_mut(id) {                      let _ = channel.send(window.raw.is_minimized());                  } @@ -1210,7 +1222,7 @@ fn run_action<P, C>(                      window.raw.set_minimized(minimized);                  }              } -            window::Action::FetchPosition(id, channel) => { +            window::Action::GetPosition(id, channel) => {                  if let Some(window) = window_manager.get_mut(id) {                      let position = window                          .raw @@ -1250,7 +1262,7 @@ fn run_action<P, C>(                      window.raw.set_window_icon(conversion::icon(icon));                  }              } -            window::Action::FetchMode(id, channel) => { +            window::Action::GetMode(id, channel) => {                  if let Some(window) = window_manager.get_mut(id) {                      let mode = if window.raw.is_visible().unwrap_or(true) {                          conversion::mode(window.raw.fullscreen()) @@ -1304,7 +1316,7 @@ fn run_action<P, C>(                      }                  }              } -            window::Action::FetchRawId(id, channel) => { +            window::Action::GetRawId(id, channel) => {                  if let Some(window) = window_manager.get_mut(id) {                      let _ = channel.send(window.raw.id().into());                  } | 
