Implement window::frames subscription

... and use it in the `solar_system` example 🎉
This commit is contained in:
Héctor Ramón Jiménez 2023-01-12 04:35:41 +01:00
parent c649ec8cf7
commit 0b86c4a299
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
4 changed files with 43 additions and 4 deletions

View file

@ -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<Instant> {
subscription::raw_events(|event, _status| match event {
crate::Event::Window(Event::RedrawRequested(at)) => Some(at),
_ => None,
})
}