mixinafReflux::Images

afReflux::Images

@Js

(Service) - Maintains a cache of Images, ensuring they are disposed of properly.

A common usage is to create an Icons class in your project that keeps tabs on the file mappings:

using afIoc::Inject
using afReflux::Images
using gfx::Image

class Icons {
    @Inject private Images images
    
    private new make(|This| in) { in(this) }
    
    Image icoImage1() { get("image1.png") }
    Image icoImage2() { get("image2.png") }
    Image icoImage3() { get("image3.png") }

    Image get(Str name) {
        images[`fan://${typeof.pod.name}/res/icons/${name}`]
    }
}

Then the icons may be referenced with:

icon := icons.icoImage1

Don't forget to add the image directory to resDirs in the build.fan:

resDirs = [`res/icons/`]
contains

Source

abstract Bool contains(Uri uri)

Returns true if an image is mapped to the given URI.

disposeAll

Source

abstract Void disposeAll()

Disposes of all the images. This is called on registry shutdown. The AppModule config key is afReflux.disposeOfImages.

get

Source

@Operator
abstract Image? get(Uri uri, Bool checked := true)

Returns (and caches) the image at the given URI.

getFaded

Source

abstract Image? getFaded(Uri uri, Bool checked := true)

Returns (and caches) a faded version of the image at the given URI. Useful for generating disabled icons.

load

Source

abstract Image? load(Uri uri, Bool checked := true)

Returns (and does not cache) the image at the given URI ensuring that it is fully loaded and that its size() is available.

set

Source

@Operator
abstract Void set(Uri uri, Image image)

Stashes the image under the given URI. If another image existed under the same URI, it is disposed of.