iced_runtime/
image.rs

1//! Allocate images explicitly to control presentation.
2use crate::core::image::Handle;
3use crate::futures::futures::channel::oneshot;
4use crate::task::{self, Task};
5
6pub use crate::core::image::{Allocation, Error};
7
8/// An image action.
9#[derive(Debug)]
10pub enum Action {
11    /// Allocates the given [`Handle`].
12    Allocate(Handle, oneshot::Sender<Result<Allocation, Error>>),
13}
14
15/// Allocates an image [`Handle`].
16///
17/// When you obtain an [`Allocation`] explicitly, you get the guarantee
18/// that using a [`Handle`] will draw the corresponding image immediately
19/// in the next frame.
20pub fn allocate(handle: impl Into<Handle>) -> Task<Result<Allocation, Error>> {
21    task::oneshot(|sender| crate::Action::Image(Action::Allocate(handle.into(), sender)))
22}