Skip to main content

Font

Struct Font 

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

Holds a font for rendering. See also: Font::draw.

Implementations§

Source§

impl Font

Source

pub fn with_ttf(ctx: &mut Context, ttf_data: Vec<u8>) -> Result<Font, Error>

Creates a new font renderer using the given .ttf file as a font.

The font is rasterized with rusttype.

Source

pub fn with_font8x8(ctx: &mut Context, smoothed: bool) -> Font

Creates a new font renderer using the font8x8 font.

If smoothed is true, glyphs which are bigger than 8 physical pixels will be linearly interpolated when stretching (smooth but blurry). If false, nearest-neighbor interpolation is used (crisp but pixelated).

Source

pub fn draw<'a, S: Into<String>>( &self, ctx: &'a mut GraphicsContext<'_>, text: S, x: f32, y: f32, font_size: f32, ) -> Text<'a>

Creates a Text struct, which you can render after specifying your parameters by modifying it.

§Usage
// Initialize the font once somewhere, usually before the game loop:
let font = fae::Font::with_font8x8(&mut ctx, true);

// Then in rendering code, call draw:
let mut ctx = ctx.start_frame(width, height, dpi_factor);
font.draw(&mut ctx, "Hello, World!", 10.0, 10.0, 12.0)
    .color((0.8, 0.5, 0.1, 1.0))
    .finish();
Source

pub fn is_glyph_cache_full(&self, ctx: &GraphicsContext<'_>) -> bool

Returns true if this font failed to draw a glyph last frame because the glyph cache was full. Generally, this should become false on the next frame because the glyph cache is resized at the start of the frame, as needed. Resizing is limited by GL_MAX_TEXTURE_SIZE however, so low-end systems might reach a limit if you’re drawing lots of very large text using many symbols.

§What to do if the glyph cache is full

Consider using alternative means of rendering large text, or increase your application’s GPU capability requirements.

Source

pub fn spritesheet(&self) -> &Spritesheet

Returns the underlying draw call of this font. Can be used to render the glyph cache texture, which is useful for debugging rasterization, glyph rendering, or other glyph-cache-related problems.

Trait Implementations§

Source§

impl Clone for Font

Source§

fn clone(&self) -> Font

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Font

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Font

§

impl RefUnwindSafe for Font

§

impl Send for Font

§

impl Sync for Font

§

impl Unpin for Font

§

impl UnsafeUnpin for Font

§

impl UnwindSafe for Font

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.