iced-yoda/native/src/window.rs

51 lines
1.4 KiB
Rust
Raw Normal View History

//! Build window-based GUI applications.
mod action;
mod event;
2022-10-19 22:56:00 -03:00
mod icon;
2022-06-21 15:59:45 -03:00
mod id;
mod mode;
mod position;
mod redraw_request;
2023-01-18 15:17:20 -08:00
mod settings;
mod user_attention;
pub use action::Action;
pub use event::Event;
2022-10-19 22:56:00 -03:00
pub use icon::Icon;
2022-06-21 15:59:45 -03:00
pub use id::Id;
pub use mode::Mode;
2022-10-19 22:56:00 -03:00
pub use position::Position;
pub use redraw_request::RedrawRequest;
2023-01-18 15:17:20 -08:00
pub use settings::Settings;
pub use user_attention::UserAttention;
use crate::subscription::{self, Subscription};
use crate::time::Instant;
2023-02-15 14:31:16 -08:00
use crate::window;
/// Subscribes to the frames of the window of the running application.
///
/// The resulting [`Subscription`] will produce items at a rate equal to the
/// 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.
2023-02-15 11:28:36 -08:00
pub fn frames() -> Subscription<Frame> {
subscription::raw_events(|event, _status| match event {
2023-02-15 11:28:36 -08:00
crate::Event::Window(id, Event::RedrawRequested(at)) => {
Some(Frame { id, at })
}
_ => None,
})
}
2023-02-15 11:28:36 -08:00
/// The returned `Frame` for a framerate subscription.
#[derive(Debug)]
pub struct Frame {
2023-02-15 14:31:16 -08:00
/// The `window::Id` that the `Frame` was produced in.
2023-02-15 11:28:36 -08:00
pub id: Id,
2023-02-15 14:31:16 -08:00
/// The `Instant` at which the frame was produced.
2023-02-15 11:28:36 -08:00
pub at: Instant,
}