[−][src]Struct elefont::FontCache
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]
&mut self,
key: Glyph
) -> Result<(Metrics, TextureGlyph), CacheError>
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]
&'a mut self,
string: &str
) -> impl 'a + Iterator<Item = Result<(Metrics, TextureGlyph), CacheError>>
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,
T: Unpin,
impl<T> !UnwindSafe for FontCache<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,