Trait egui::load::ImageLoader

source ·
pub trait ImageLoader {
    // Required methods
    fn id(&self) -> &str;
    fn load(
        &self,
        ctx: &Context,
        uri: &str,
        size_hint: SizeHint
    ) -> ImageLoadResult;
    fn forget(&self, uri: &str);
    fn forget_all(&self);
    fn byte_size(&self) -> usize;

    // Provided method
    fn end_frame(&self, frame_index: usize) { ... }
}
Expand description

An ImageLoader decodes raw bytes into a ColorImage.

Implementations are expected to cache at least each URI.

Required Methods§

source

fn id(&self) -> &str

Unique ID of this loader.

To reduce the chance of collisions, include module_path!() as part of this ID.

For example: concat!(module_path!(), "::MyLoader") for my_crate::my_loader::MyLoader.

source

fn load(&self, ctx: &Context, uri: &str, size_hint: SizeHint) -> ImageLoadResult

Try loading the image from the given uri.

Implementations should call ctx.request_repaint to wake up the ui once the image is ready.

The implementation should cache any result, so that calling this is immediate-mode safe.

Errors

This may fail with:

source

fn forget(&self, uri: &str)

Forget the given uri.

If uri is cached, it should be evicted from cache, so that it may be fully reloaded.

source

fn forget_all(&self)

Forget all URIs ever given to this loader.

If the loader caches any URIs, the entire cache should be cleared, so that all of them may be fully reloaded.

source

fn byte_size(&self) -> usize

If the loader caches any data, this should return the size of that cache.

Provided Methods§

source

fn end_frame(&self, frame_index: usize)

Implementations may use this to perform work at the end of a frame, such as evicting unused entries from a cache.

Implementors§