Skip to main content

image_cache

Function image_cache 

Source
pub fn image_cache(
    image_cache_provider: impl ImageCacheProvider,
) -> ImageCacheElement
Expand description

Scopes an image cache to the img elements below it.

Each image in the children uses the cache that image_cache_provider returns, instead of the app-wide cache. Pass an Entity of an ImageCache to share one cache, or retain_all to get a cache that lives with this element’s state. The provider is called on every layout and paint.

Only crate::ImageSource::Resource sources use the cache. See crate::Img::image_cache.

§Examples

let gallery = image_cache(retain_all("gallery")).children((0..3).map(|ix| {
    img(format!("https://example.com/photos/{ix}.jpg"))
        .size(px(120.))
        .into_any_element()
}));