cosmic::iced::widget::canvas

Type Alias Cache

source
pub type Cache<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> { /* private fields */ }

Implementations

source§

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

source

pub fn new() -> Cache<Renderer>

Creates a new empty Cache.

source

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.

source

pub fn clear(&self)

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

source

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

source§

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

source§

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

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> Cache<Renderer>

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