Struct tetra::graphics::text::Font [−][src]
A font with an associated size, cached on the GPU.
Performance
Creating a Font
is a relatively expensive operation. If you can, store them in your State
struct rather than recreating them each frame.
Cloning a Font
is a very cheap operation, as the underlying data is shared between the
original instance and the clone via reference-counting.
Examples
The text
example demonstrates how to load a font and then draw some text.
Implementations
impl Font
[src]
pub fn vector<P>(ctx: &mut Context, path: P, size: f32) -> Result<Font> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Creates a Font
from a vector font file, with the given size.
TrueType and OpenType fonts are supported.
If you want to load multiple sizes of the same font, you can use a
VectorFontBuilder
to avoid loading/parsing the file multiple times.
Errors
TetraError::FailedToLoadAsset
will be returned if the file could not be loaded.TetraError::InvalidFont
will be returned if the font data was invalid.TetraError::PlatformError
will be returned if the GPU cache for the font could not be created.
pub fn from_vector_file_data(
ctx: &mut Context,
data: &'static [u8],
size: f32
) -> Result<Font>
[src]
ctx: &mut Context,
data: &'static [u8],
size: f32
) -> Result<Font>
Creates a Font
from a slice of binary data.
TrueType and OpenType fonts are supported.
This is useful in combination with include_bytes
, as it
allows you to include your font data directly in the binary.
If you want to load multiple sizes of the same font, you can use a
VectorFontBuilder
to avoid parsing the data multiple times.
Errors
TetraError::InvalidFont
will be returned if the font data was invalid.TetraError::PlatformError
will be returned if the GPU cache for the font could not be created.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Font
[src]
impl !Send for Font
[src]
impl !Sync for Font
[src]
impl Unpin for Font
[src]
impl !UnwindSafe for Font
[src]
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,
pub 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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub 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>,