pub struct IMAGES;Expand description
Image loading, cache and render service.
If the app is running without a VIEW_PROCESS all images are dummy, see load_in_headless for
details.
Implementations§
Source§impl IMAGES
impl IMAGES
Sourcepub fn load_in_headless(&self) -> Var<bool>
pub fn load_in_headless(&self) -> Var<bool>
If should still download/read image bytes in headless/renderless mode.
When an app is in headless mode without renderer no VIEW_PROCESS is available, so
images cannot be decoded, in this case all images are dummy loading and no attempt
to download/read the image files is made. You can enable loading in headless tests to detect
IO errors, in this case if there is an error acquiring the image file the image will be a
dummy with error.
Sourcepub fn limits(&self) -> Var<ImageLimits>
pub fn limits(&self) -> Var<ImageLimits>
Default loading and decoding limits for each image.
Sourcepub fn read(&self, path: impl Into<PathBuf>) -> Var<ImageEntry>
pub fn read(&self, path: impl Into<PathBuf>) -> Var<ImageEntry>
Request an image, reads from a path and caches it.
This is shorthand for calling IMAGES.image with ImageSource::Read and ImageOptions::cache.
Sourcepub fn download<U>(&self, uri: U, accept: Option<Txt>) -> Var<ImageEntry>
pub fn download<U>(&self, uri: U, accept: Option<Txt>) -> Var<ImageEntry>
Request an image, downloads from an uri and caches it.
Optionally define the HTTP ACCEPT header, if not set all image formats supported by the view-process backend are accepted.
This is shorthand for calling IMAGES.image with ImageSource::Download and ImageOptions::cache.
Sourcepub fn from_static(
&self,
data: &'static [u8],
format: impl Into<ImageDataFormat>,
) -> Var<ImageEntry>
pub fn from_static( &self, data: &'static [u8], format: impl Into<ImageDataFormat>, ) -> Var<ImageEntry>
Request an image from &'static [u8] data.
The data can be any of the formats described in ImageDataFormat.
This is shorthand for calling IMAGES.image with ImageSource::Data and ImageOptions::cache.
§Examples
Get an image from a PNG file embedded in the app executable using include_bytes!.
let image_var = IMAGES.from_static(include_bytes!("ico.png"), "png");Sourcepub fn from_data(
&self,
data: IpcBytes,
format: impl Into<ImageDataFormat>,
) -> Var<ImageEntry>
pub fn from_data( &self, data: IpcBytes, format: impl Into<ImageDataFormat>, ) -> Var<ImageEntry>
Get a cached image from shared data.
The data can be any of the formats described in ImageDataFormat.
This is shorthand for calling IMAGES.image with ImageSource::Data and ImageOptions::cache.
Sourcepub fn image(
&self,
source: impl Into<ImageSource>,
options: ImageOptions,
limits: Option<ImageLimits>,
) -> Var<ImageEntry>
pub fn image( &self, source: impl Into<ImageSource>, options: ImageOptions, limits: Option<ImageLimits>, ) -> Var<ImageEntry>
Request an image, with full load and cache configuration.
If limits is None the IMAGES.limits is used.
Always returns a loading image due to the deferred nature of services. If the image is already in cache it will be set and bound to it once the current update finishes.
Sourcepub fn image_task<F>(
&self,
source: impl IntoFuture<IntoFuture = F>,
options: ImageOptions,
limits: Option<ImageLimits>,
) -> Var<ImageEntry>
pub fn image_task<F>( &self, source: impl IntoFuture<IntoFuture = F>, options: ImageOptions, limits: Option<ImageLimits>, ) -> Var<ImageEntry>
Await for an image source, then get or load the image.
If limits is None the IMAGES.limits is used.
This method returns immediately with a loading ImageVar, when source is ready it
is used to get the actual ImageVar and binds it to the returned image.
Note that the cache_mode always applies to the inner image, and only to the return image if cache_key is set.
Sourcepub fn register(
&self,
key: Option<ImageHash>,
image: (ViewImageHandle, ImageDecoded),
) -> Var<ImageEntry>
pub fn register( &self, key: Option<ImageHash>, image: (ViewImageHandle, ImageDecoded), ) -> Var<ImageEntry>
Associate the image produced by direct interaction with the view-process with the key in the cache.
Returns an image var that tracks the image, note that if the key is already known does not use the image data.
Note that you can register entries in ImageEntry::insert_entry, this method is only for tracking a new entry.
Note that the image will not automatically restore on respawn if the view-process fails while decoding.
Sourcepub fn clean(&self, key: ImageHash)
pub fn clean(&self, key: ImageHash)
Remove the image from the cache, if it is only held by the cache.
You can use ImageSource::hash128_read and ImageSource::hash128_download to get the key
for files or downloads.
Sourcepub fn purge(&self, key: ImageHash)
pub fn purge(&self, key: ImageHash)
Remove the image from the cache, even if it is still referenced outside of the cache.
You can use ImageSource::hash128_read and ImageSource::hash128_download to get the key
for files or downloads.
Sourcepub fn cache_key(&self, image: &ImageEntry) -> Option<ImageHash>
pub fn cache_key(&self, image: &ImageEntry) -> Option<ImageHash>
Gets the cache key of an image.
Sourcepub fn is_cached(&self, image: &ImageEntry) -> bool
pub fn is_cached(&self, image: &ImageEntry) -> bool
If the image is cached.
Sourcepub fn purge_all(&self)
pub fn purge_all(&self)
Clear all cached images, including images that are still referenced outside of the cache.
Image memory only drops when all strong references are removed, so if an image is referenced outside of the cache it will merely be disconnected from the cache by this method.
Sourcepub fn extend(&self, extension: Box<dyn ImagesExtension>)
pub fn extend(&self, extension: Box<dyn ImagesExtension>)
Add an images service extension.
See ImagesExtension for extension capabilities.
Sourcepub fn available_formats(&self) -> Vec<ImageFormat>
pub fn available_formats(&self) -> Vec<ImageFormat>
Image formats implemented by the current view-process and extensions.
Source§impl IMAGES
impl IMAGES
Sourcepub fn render<N, R>(
&self,
mask: Option<ImageMaskMode>,
render: N,
) -> Var<ImageEntry>
pub fn render<N, R>( &self, mask: Option<ImageMaskMode>, render: N, ) -> Var<ImageEntry>
Render the window generated by render to an image.
The window is created as a headless surface and rendered to the returned image. You can set the
IMAGE_RENDER.retain var inside render to create an image that updates with new frames. By default it will only render once.
The closure runs in the WINDOW context of the headless window.
This is shorthand for calling IMAGES.image with ImageSource::render and ImageOptions::none.
Sourcepub fn render_node(
&self,
render_mode: RenderMode,
mask: Option<ImageMaskMode>,
render: impl FnOnce() -> UiNode + Send + Sync + 'static,
) -> Var<ImageEntry>
pub fn render_node( &self, render_mode: RenderMode, mask: Option<ImageMaskMode>, render: impl FnOnce() -> UiNode + Send + Sync + 'static, ) -> Var<ImageEntry>
Render an UiNode to an image.
This method is a shortcut to render a node without needing to declare the headless window, note that
a headless window is still used, the node does not have the same context as the calling widget.
This is shorthand for calling IMAGES.image with ImageSource::render_node and ImageOptions::none.
Trait Implementations§
Source§impl IMAGES_Ext for IMAGES
impl IMAGES_Ext for IMAGES
Source§fn watch(&self, path: impl Into<PathBuf>) -> ImageVar
fn watch(&self, path: impl Into<PathBuf>) -> ImageVar
IMAGES.read with automatic reload when the file at path is modified.Source§fn watch_image(
&self,
path: impl Into<PathBuf>,
options: ImageOptions,
limits: Option<ImageLimits>,
) -> ImageVar
fn watch_image( &self, path: impl Into<PathBuf>, options: ImageOptions, limits: Option<ImageLimits>, ) -> ImageVar
IMAGES.image with automatic cache reload when the file at path is modified.Auto Trait Implementations§
impl Freeze for IMAGES
impl RefUnwindSafe for IMAGES
impl Send for IMAGES
impl Sync for IMAGES
impl Unpin for IMAGES
impl UnwindSafe for IMAGES
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more