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.
§Provider
This service is provided by the ImageManager extension, it will panic if used in an app not extended.
Implementations§
Source§impl IMAGES
impl IMAGES
Sourcepub fn render<N, R>(&self, mask: Option<ImageMaskMode>, render: N) -> ImageVar
pub fn render<N, R>(&self, mask: Option<ImageMaskMode>, render: N) -> ImageVar
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.
Sourcepub fn render_node(
&self,
render_mode: RenderMode,
scale_factor: impl Into<Factor>,
mask: Option<ImageMaskMode>,
render: impl FnOnce() -> UiNode + Send + Sync + 'static,
) -> ImageVar
pub fn render_node( &self, render_mode: RenderMode, scale_factor: impl Into<Factor>, mask: Option<ImageMaskMode>, render: impl FnOnce() -> UiNode + Send + Sync + 'static, ) -> ImageVar
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 the dummy image 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 dummy(&self, error: Option<Txt>) -> ImageVar
pub fn dummy(&self, error: Option<Txt>) -> ImageVar
Returns a dummy image that reports it is loaded or an error.
Sourcepub fn read(&self, path: impl Into<PathBuf>) -> ImageVar
pub fn read(&self, path: impl Into<PathBuf>) -> ImageVar
Cache or load an image file from a file system path.
Sourcepub fn download(&self, uri: impl TryUri, accept: Option<Txt>) -> ImageVar
pub fn download(&self, uri: impl TryUri, accept: Option<Txt>) -> ImageVar
Get a cached uri or download it.
Optionally define the HTTP ACCEPT header, if not set all image formats supported by the view-process backend are accepted.
Sourcepub fn from_static(
&self,
data: &'static [u8],
format: impl Into<ImageDataFormat>,
) -> ImageVar
pub fn from_static( &self, data: &'static [u8], format: impl Into<ImageDataFormat>, ) -> ImageVar
Get a cached image from &'static [u8] data.
The data can be any of the formats described in ImageDataFormat.
The image key is a ImageHash of the image data.
§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: Arc<Vec<u8>>,
format: impl Into<ImageDataFormat>,
) -> ImageVar
pub fn from_data( &self, data: Arc<Vec<u8>>, format: impl Into<ImageDataFormat>, ) -> ImageVar
Get a cached image from shared data.
The image key is a ImageHash of the image data. The data reference is held only until the image is decoded.
The data can be any of the formats described in ImageDataFormat.
Sourcepub fn cache(&self, source: impl Into<ImageSource>) -> ImageVar
pub fn cache(&self, source: impl Into<ImageSource>) -> ImageVar
Get a cached image or add it to the cache.
Sourcepub fn retry(&self, source: impl Into<ImageSource>) -> ImageVar
pub fn retry(&self, source: impl Into<ImageSource>) -> ImageVar
Get a cached image or add it to the cache or retry if the cached image is an error.
Sourcepub fn reload(&self, source: impl Into<ImageSource>) -> ImageVar
pub fn reload(&self, source: impl Into<ImageSource>) -> ImageVar
Load an image, if it was already cached update the cached image with the reloaded data.
Sourcepub fn image(
&self,
source: impl Into<ImageSource>,
cache_mode: impl Into<ImageCacheMode>,
limits: Option<ImageLimits>,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> ImageVar
pub fn image( &self, source: impl Into<ImageSource>, cache_mode: impl Into<ImageCacheMode>, limits: Option<ImageLimits>, downscale: Option<ImageDownscale>, mask: Option<ImageMaskMode>, ) -> ImageVar
Get or load an image.
If limits is None the IMAGES.limits is used.
Sourcepub fn image_task<F>(
&self,
source: impl IntoFuture<IntoFuture = F>,
cache_mode: impl Into<ImageCacheMode>,
cache_key: Option<ImageHash>,
limits: Option<ImageLimits>,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> ImageVar
pub fn image_task<F>( &self, source: impl IntoFuture<IntoFuture = F>, cache_mode: impl Into<ImageCacheMode>, cache_key: Option<ImageHash>, limits: Option<ImageLimits>, downscale: Option<ImageDownscale>, mask: Option<ImageMaskMode>, ) -> ImageVar
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: ImageHash,
image: ViewImage,
) -> Result<ImageVar, (ViewImage, ImageVar)>
pub fn register( &self, key: ImageHash, image: ViewImage, ) -> Result<ImageVar, (ViewImage, ImageVar)>
Associate the image with the key in the cache.
Returns Ok(ImageVar) with the new image var that tracks image, or Err(ViewImage, ImageVar)
that returns the image and a clone of the var already associated with the key.
Sourcepub fn clean(&self, key: ImageHash) -> bool
pub fn clean(&self, key: ImageHash) -> bool
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.
Returns true if the image was removed.
Sourcepub fn purge(&self, key: &ImageHash) -> bool
pub fn purge(&self, key: &ImageHash) -> bool
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.
Returns true if the image was cached.
Sourcepub fn detach(&self, image: ImageVar) -> ImageVar
pub fn detach(&self, image: ImageVar) -> ImageVar
Returns an image that is not cached.
If the image is the only reference returns it and removes it from the cache. If there are other
references a new ImageVar is generated from a clone of the image.
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 install_proxy(&self, proxy: Box<dyn ImageCacheProxy>)
pub fn install_proxy(&self, proxy: Box<dyn ImageCacheProxy>)
Add a cache proxy.
Proxies can intercept cache requests and map to a different request or return an image directly.
Sourcepub fn available_decoders(&self) -> Vec<Txt>
pub fn available_decoders(&self) -> Vec<Txt>
Image format decoders implemented by the current view-process.
Each text is the lower-case file extension, without the dot.
Sourcepub fn available_encoders(&self) -> Vec<Txt>
pub fn available_encoders(&self) -> Vec<Txt>
Image format encoders implemented by the current view-process.
Each text is the lower-case file extension, without the dot.
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> 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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