Type Alias Cache

pub type Cache<Renderer = Renderer<Renderer, Renderer>> = Cache<Renderer>;
Expand description

A simple cache that stores generated Geometry to avoid recomputation.

A Cache will not redraw its geometry unless the dimensions of its layer change or it is explicitly cleared.

Aliased Type§

struct Cache<Renderer = Renderer<Renderer, Renderer>> { /* private fields */ }

Implementations

§

impl<Renderer> Cache<Renderer>
where Renderer: Renderer,

pub fn new() -> Cache<Renderer>

Creates a new empty [Cache].

pub fn with_group(group: Group) -> Cache<Renderer>

Creates a new empty [Cache] with the given Group.

Caches within the same group may reuse internal rendering storage.

You should generally group caches that are likely to change together.

pub fn clear(&self)

Clears the [Cache], forcing a redraw the next time it is used.

pub fn draw( &self, renderer: &Renderer, bounds: Size, draw_fn: impl FnOnce(&mut Frame<Renderer>), ) -> <Renderer as Renderer>::Geometry

Draws geometry using the provided closure and stores it in the [Cache].

The closure will only be called when

  • the bounds have changed since the previous draw call.
  • the [Cache] is empty or has been explicitly cleared.

Otherwise, the previously stored geometry will be returned. The [Cache] is not cleared in this case. In other words, it will keep returning the stored geometry if needed.

Trait Implementations

§

impl<Renderer> Debug for Cache<Renderer>
where Renderer: Renderer, <<Renderer as Renderer>::Geometry as Cached>::Cache: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<Renderer> Default for Cache<Renderer>
where Renderer: Renderer,

§

fn default() -> Cache<Renderer>

Returns the “default value” for a type. Read more