summaryrefslogtreecommitdiffstats
path: root/runtime/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-07-06 07:00:15 +0200
committerLibravatar GitHub <noreply@github.com>2023-07-06 07:00:15 +0200
commit7f805bc5dd9ed38c904d83f9ea931eed6f3234bf (patch)
tree6f0b38ab20b8fa91e5bbcc001a5738bb83d5f20a /runtime/src
parenta057f8811bfc47afc4271f05b92263a19122d888 (diff)
parentf350a2f812487af9a43c36e28d9b904e76a66474 (diff)
downloadiced-7f805bc5dd9ed38c904d83f9ea931eed6f3234bf.tar.gz
iced-7f805bc5dd9ed38c904d83f9ea931eed6f3234bf.tar.bz2
iced-7f805bc5dd9ed38c904d83f9ea931eed6f3234bf.zip
Merge pull request #1927 from thunderstorm010/master
Add command to retrieve window size
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/window.rs12
-rw-r--r--runtime/src/window/action.rs19
2 files changed, 18 insertions, 13 deletions
diff --git a/runtime/src/window.rs b/runtime/src/window.rs
index e448edef..5219fbfd 100644
--- a/runtime/src/window.rs
+++ b/runtime/src/window.rs
@@ -9,6 +9,7 @@ pub use screenshot::Screenshot;
use crate::command::{self, Command};
use crate::core::time::Instant;
use crate::core::window::{Event, Icon, Level, Mode, UserAttention};
+use crate::core::Size;
use crate::futures::subscription::{self, Subscription};
/// Subscribes to the frames of the window of the running application.
@@ -37,8 +38,15 @@ pub fn drag<Message>() -> Command<Message> {
}
/// Resizes the window to the given logical dimensions.
-pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
- Command::single(command::Action::Window(Action::Resize { width, height }))
+pub fn resize<Message>(new_size: Size<u32>) -> Command<Message> {
+ Command::single(command::Action::Window(Action::Resize(new_size)))
+}
+
+/// Fetches the current window size in logical dimensions.
+pub fn fetch_size<Message>(
+ f: impl FnOnce(Size<u32>) -> Message + 'static,
+) -> Command<Message> {
+ Command::single(command::Action::Window(Action::FetchSize(Box::new(f))))
}
/// Maximizes the window.
diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs
index 09be1810..b6964e36 100644
--- a/runtime/src/window/action.rs
+++ b/runtime/src/window/action.rs
@@ -1,4 +1,5 @@
use crate::core::window::{Icon, Level, Mode, UserAttention};
+use crate::core::Size;
use crate::futures::MaybeSend;
use crate::window::Screenshot;
@@ -15,12 +16,9 @@ pub enum Action<T> {
/// button was pressed immediately before this function is called.
Drag,
/// Resize the window.
- Resize {
- /// The new logical width of the window
- width: u32,
- /// The new logical height of the window
- height: u32,
- },
+ Resize(Size<u32>),
+ /// Fetch the current size of the window.
+ FetchSize(Box<dyn FnOnce(Size<u32>) -> T + 'static>),
/// Set the window to maximized or back
Maximize(bool),
/// Set the window to minimized or back
@@ -106,7 +104,8 @@ impl<T> Action<T> {
match self {
Self::Close => Action::Close,
Self::Drag => Action::Drag,
- Self::Resize { width, height } => Action::Resize { width, height },
+ Self::Resize(size) => Action::Resize(size),
+ Self::FetchSize(o) => Action::FetchSize(Box::new(move |s| f(o(s)))),
Self::Maximize(maximized) => Action::Maximize(maximized),
Self::Minimize(minimized) => Action::Minimize(minimized),
Self::Move { x, y } => Action::Move { x, y },
@@ -135,10 +134,8 @@ impl<T> fmt::Debug for Action<T> {
match self {
Self::Close => write!(f, "Action::Close"),
Self::Drag => write!(f, "Action::Drag"),
- Self::Resize { width, height } => write!(
- f,
- "Action::Resize {{ widget: {width}, height: {height} }}"
- ),
+ Self::Resize(size) => write!(f, "Action::Resize({size:?})"),
+ Self::FetchSize(_) => write!(f, "Action::FetchSize"),
Self::Maximize(maximized) => {
write!(f, "Action::Maximize({maximized})")
}