IMAGES

Struct IMAGES 

Source
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

Source

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.

Source

pub fn limits(&self) -> Var<ImageLimits>

Default loading and decoding limits for each image.

Source

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.

Source

pub fn download<U>(&self, uri: U, accept: Option<Txt>) -> Var<ImageEntry>
where U: TryInto<Uri>, <U as TryInto<Uri>>::Error: ToTxt,

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.

Source

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");
Source

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.

Source

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.

Source

pub fn image_task<F>( &self, source: impl IntoFuture<IntoFuture = F>, options: ImageOptions, limits: Option<ImageLimits>, ) -> Var<ImageEntry>
where F: Future<Output = ImageSource> + Send + 'static,

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.

Source

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.

Source

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.

Source

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.

Source

pub fn cache_key(&self, image: &ImageEntry) -> Option<ImageHash>

Gets the cache key of an image.

Source

pub fn is_cached(&self, image: &ImageEntry) -> bool

If the image is cached.

Source

pub fn clean_all(&self)

Clear cached images that are not referenced outside of the cache.

Source

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.

Source

pub fn extend(&self, extension: Box<dyn ImagesExtension>)

Add an images service extension.

See ImagesExtension for extension capabilities.

Source

pub fn available_formats(&self) -> Vec<ImageFormat>

Image formats implemented by the current view-process and extensions.

Source§

impl IMAGES

Source

pub fn render<N, R>( &self, mask: Option<ImageMaskMode>, render: N, ) -> Var<ImageEntry>
where N: FnOnce() -> R + Send + Sync + 'static, R: ImageRenderWindowRoot,

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.

Source

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

Source§

fn watch(&self, path: impl Into<PathBuf>) -> ImageVar

Like 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

Like 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> StateValue for T
where T: Any + Send + Sync,