[][src]Struct elefont::FontCache

pub struct FontCache<T: Texture> { /* fields omitted */ }

The main structure for maintaing a cache of rendered glyphs

FontCache is specifically an intermediary step. It doesn't understand how to read font files or how to break up a string into glyphs: that's handled by the FontProvider. It doesn't handle sending glyphs to the GPU: if you want to do that, provide a Texture that stores its data on the GPU. What it does do is keep track of which glyphs have already been rendered, where they were stored, and provide a consistent API over a variety of ways of rendering characters.

Methods

impl<T: Texture> FontCache<T>[src]

pub fn new(font: Box<dyn FontProvider>, texture: T) -> Self[src]

Create a new FontCache that pulls from the given provider and renders to the provided texture

pub fn clear(&mut self)[src]

Forget the position of the characters in the texture, and re-set the cursor.

This doesn't set any data in the Texture! Old glyphs may continue to work, but this is akin to a use-after-free.

pub fn render_glyph(
    &mut self,
    key: Glyph
) -> Result<(Metrics, TextureGlyph), CacheError>
[src]

Render a glyph to the texture

pub fn render_string<'a>(
    &'a mut self,
    string: &str
) -> impl 'a + Iterator<Item = Result<(Metrics, TextureGlyph), CacheError>>
[src]

Attempt to convert a string into a series of glyphs or errors

Before being converted, the string is normalized if the "unicode-normalilzation" feature is activated, and whitespace characters are removed.

pub fn cache_string(&mut self, string: &str) -> Result<(), CacheError>[src]

Cache a string or return an error if one occurred

This can be useful if the entire domain of the possible glyphs is known beforehand (like a bitmap font.) Under the hood, this just calls [render_string] and ignores the returned glyphs.

pub fn replace_texture(&mut self, texture: T) -> T[src]

Swap out the internal texture for another one

This will clear the cache automatically, to avoid holding references to invalid areas of the texture

pub fn texture(&self) -> &T[src]

pub fn font(&self) -> &dyn FontProvider[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for FontCache<T>

impl<T> !Send for FontCache<T>

impl<T> !Sync for FontCache<T>

impl<T> Unpin for FontCache<T> where
    T: Unpin

impl<T> !UnwindSafe for FontCache<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.