Skip to main content

LayoutCache

Struct LayoutCache 

Source
pub struct LayoutCache { /* private fields */ }
Expand description

Keeps the last layout of one widget’s text and recomputes it only when an input changes.

Implementations§

Source§

impl LayoutCache

Source

pub fn new() -> Self

Creates an empty cache.

§Returns

The new LayoutCache.

Source

pub fn get( &mut self, engine: &mut dyn TextLayout, text: &str, style: &TextStyle, max_width: Option<u32>, ) -> &LaidOut

Returns the layout for the inputs, computing it with engine only if the text, font, font size, font style or width differ from the previous call. Changing only the color or the justification does not lay out again.

§Arguments
  • engine - The layout engine to use on a miss.
  • text - The text to lay out.
  • style - The font, size and style.
  • max_width - The width in pixels at which to wrap, or None for no wrapping.
§Returns

The cached or freshly computed layout.

Source

pub fn invalidate(&mut self)

Forgets the cached layout so the next get lays out again.

Source

pub fn layouts(&self) -> usize

How many times the engine has been asked to lay out (cache misses).

§Returns

The number of layouts computed so far.

Trait Implementations§

Source§

impl Default for LayoutCache

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.