From 0b86c4a299d384cafca31206eac8c94f1123518d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 12 Jan 2023 04:35:41 +0100 Subject: Implement `window::frames` subscription ... and use it in the `solar_system` example :tada: --- native/src/window.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'native/src/window.rs') diff --git a/native/src/window.rs b/native/src/window.rs index 1b97e655..4bccc471 100644 --- a/native/src/window.rs +++ b/native/src/window.rs @@ -8,3 +8,18 @@ pub use action::Action; pub use event::Event; pub use mode::Mode; pub use user_attention::UserAttention; + +use crate::subscription::{self, Subscription}; + +use std::time::Instant; + +/// Subscribes to the frames of the window of the running application. +/// +/// The resulting [`Subscription`] will produce items at a rate equal to the +/// framerate of the monitor of said window. +pub fn frames() -> Subscription { + subscription::raw_events(|event, _status| match event { + crate::Event::Window(Event::RedrawRequested(at)) => Some(at), + _ => None, + }) +} -- cgit From e2ddef74387bcd81859b56e47316c47d7b739a01 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 12 Jan 2023 05:18:25 +0100 Subject: Replace `Option` with `RedrawRequest` enum --- native/src/window.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'native/src/window.rs') diff --git a/native/src/window.rs b/native/src/window.rs index 4bccc471..6ebe15b1 100644 --- a/native/src/window.rs +++ b/native/src/window.rs @@ -2,11 +2,13 @@ mod action; mod event; mod mode; +mod redraw_request; mod user_attention; pub use action::Action; pub use event::Event; pub use mode::Mode; +pub use redraw_request::RedrawRequest; pub use user_attention::UserAttention; use crate::subscription::{self, Subscription}; -- cgit From fc54d6ba31246157422d092914ba7c1e483129c4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 12 Jan 2023 05:26:39 +0100 Subject: Use `instant` to fix Wasm target --- native/src/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src/window.rs') diff --git a/native/src/window.rs b/native/src/window.rs index 6ebe15b1..94201059 100644 --- a/native/src/window.rs +++ b/native/src/window.rs @@ -13,7 +13,7 @@ pub use user_attention::UserAttention; use crate::subscription::{self, Subscription}; -use std::time::Instant; +use instant::Instant; /// Subscribes to the frames of the window of the running application. /// -- cgit From c6d0046102bb6951bf0f1f6102f748199c5889e2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 12 Jan 2023 06:24:44 +0100 Subject: Use `instant` instead of `wasm-timer` in `iced_core` --- native/src/window.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'native/src/window.rs') diff --git a/native/src/window.rs b/native/src/window.rs index 94201059..bd92730d 100644 --- a/native/src/window.rs +++ b/native/src/window.rs @@ -12,8 +12,7 @@ pub use redraw_request::RedrawRequest; pub use user_attention::UserAttention; use crate::subscription::{self, Subscription}; - -use instant::Instant; +use crate::time::Instant; /// Subscribes to the frames of the window of the running application. /// -- cgit From b9c8c7b08d2778b6717c2df0731605aea35dc0a2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 13 Jan 2023 18:17:15 +0100 Subject: Clarify documentation of `window::frames` --- native/src/window.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'native/src/window.rs') diff --git a/native/src/window.rs b/native/src/window.rs index bd92730d..a5cdc8ce 100644 --- a/native/src/window.rs +++ b/native/src/window.rs @@ -17,7 +17,11 @@ use crate::time::Instant; /// Subscribes to the frames of the window of the running application. /// /// The resulting [`Subscription`] will produce items at a rate equal to the -/// framerate of the monitor of said window. +/// refresh rate of the window. Note that this rate may be variable, as it is +/// normally managed by the graphics driver and/or the OS. +/// +/// In any case, this [`Subscription`] is useful to smoothly draw application-driven +/// animations without missing any frames. pub fn frames() -> Subscription { subscription::raw_events(|event, _status| match event { crate::Event::Window(Event::RedrawRequested(at)) => Some(at), -- cgit