summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-02-22 09:33:13 +0100
committerLibravatar GitHub <noreply@github.com>2024-02-22 09:33:13 +0100
commita27267b8fbd7cfc1033c1ca9aff9a57ae57f0030 (patch)
tree4ef2366666b5df94a5dde191088c7d7385a1c788 /runtime
parentce4eef64cdde5f3e5809c963a1d84c933d27e7ae (diff)
parent9339728b6863523152fc40dd86fb78d1461c2b40 (diff)
downloadiced-a27267b8fbd7cfc1033c1ca9aff9a57ae57f0030.tar.gz
iced-a27267b8fbd7cfc1033c1ca9aff9a57ae57f0030.tar.bz2
iced-a27267b8fbd7cfc1033c1ca9aff9a57ae57f0030.zip
Merge pull request #2280 from n1ght-hunter/add-action-fetch-location
add fetch_location action
Diffstat (limited to '')
-rw-r--r--runtime/src/window.rs11
-rw-r--r--runtime/src/window/action.rs8
2 files changed, 19 insertions, 0 deletions
diff --git a/runtime/src/window.rs b/runtime/src/window.rs
index 04bcfcd8..24171e3e 100644
--- a/runtime/src/window.rs
+++ b/runtime/src/window.rs
@@ -101,6 +101,17 @@ pub fn minimize<Message>(id: Id, minimized: bool) -> Command<Message> {
Command::single(command::Action::Window(Action::Minimize(id, minimized)))
}
+/// Fetches the current window position in logical coordinates.
+pub fn fetch_position<Message>(
+ id: Id,
+ f: impl FnOnce(Option<Point>) -> Message + 'static,
+) -> Command<Message> {
+ Command::single(command::Action::Window(Action::FetchPosition(
+ id,
+ Box::new(f),
+ )))
+}
+
/// Moves the window to the given logical coordinates.
pub fn move_to<Message>(id: Id, position: Point) -> Command<Message> {
Command::single(command::Action::Window(Action::Move(id, position)))
diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs
index 9bfc2b62..e44ff5a6 100644
--- a/runtime/src/window/action.rs
+++ b/runtime/src/window/action.rs
@@ -38,6 +38,8 @@ pub enum Action<T> {
FetchMinimized(Id, Box<dyn FnOnce(Option<bool>) -> T + 'static>),
/// Set the window to minimized or back
Minimize(Id, bool),
+ /// Fetch the current logical coordinates of the window.
+ FetchPosition(Id, Box<dyn FnOnce(Option<Point>) -> T + 'static>),
/// Move the window to the given logical coordinates.
///
/// Unsupported on Wayland.
@@ -134,6 +136,9 @@ impl<T> Action<T> {
Action::FetchMinimized(id, Box::new(move |s| f(o(s))))
}
Self::Minimize(id, minimized) => Action::Minimize(id, minimized),
+ Self::FetchPosition(id, o) => {
+ Action::FetchPosition(id, Box::new(move |s| f(o(s))))
+ }
Self::Move(id, position) => Action::Move(id, position),
Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode),
Self::FetchMode(id, o) => {
@@ -186,6 +191,9 @@ impl<T> fmt::Debug for Action<T> {
Self::Minimize(id, minimized) => {
write!(f, "Action::Minimize({id:?}, {minimized}")
}
+ Self::FetchPosition(id, _) => {
+ write!(f, "Action::FetchPosition({id:?})")
+ }
Self::Move(id, position) => {
write!(f, "Action::Move({id:?}, {position})")
}