FontTexture

Struct FontTexture 

Source
pub struct FontTexture<'r> {
    pub texture: Texture<'r>,
    /* private fields */
}
Expand description

A text-rendering-enabled wrapper for Texture.

Fields§

§texture: Texture<'r>

The texture containing rendered glyphs in a tightly packed manner.

Implementations§

Source§

impl FontTexture<'_>

Source

pub fn new<T>( texture_creator: &TextureCreator<T>, ) -> Result<FontTexture<'_>, String>

Creates a new FontTexture for rendering text.

Consider the lifetimes of this structure and the given TextureCreator as you would a Texture created with one, that is why this structure is named “FontTexture”.

§Important note

Only use a single &[Font] for each FontTexture. Glyphs with the same index but different font are hard to differentiate, so using different sets of Fonts when rendering with a single FontTexture will lead to wrong results.

§Errors

The function will return an error if the Texture can’t be created, and the Err(String) will contain an error string from SDL.

Source

pub fn draw_text<RT: RenderTarget>( &mut self, canvas: &mut Canvas<RT>, fonts: &[Font], glyphs: &[GlyphPosition<Color>], ) -> Result<(), String>

Renders text to the given canvas, using the given fonts and glyphs.

The canvas should be the same one that the TextureCreator used in FontTexture::new was created from.

The font-slice should be the same one that is passed to Layout::append.

The glyphs should be from Layout::glyphs.

§Errors

This function will return an error if the Texture cannot be written to, or a copy from the texture to the canvas fails. This should only really happen under very exceptional circumstances, so text rendering is interrupted by these errors. The Err(String) will contain an informational string from SDL.

Auto Trait Implementations§

§

impl<'r> Freeze for FontTexture<'r>

§

impl<'r> RefUnwindSafe for FontTexture<'r>

§

impl<'r> !Send for FontTexture<'r>

§

impl<'r> !Sync for FontTexture<'r>

§

impl<'r> Unpin for FontTexture<'r>

§

impl<'r> UnwindSafe for FontTexture<'r>

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 = 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.