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<'_>
impl FontTexture<'_>
Sourcepub fn new<T>(
texture_creator: &TextureCreator<T>,
) -> Result<FontTexture<'_>, String>
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.
Sourcepub fn draw_text<RT: RenderTarget>(
&mut self,
canvas: &mut Canvas<RT>,
fonts: &[Font],
glyphs: &[GlyphPosition<Color>],
) -> Result<(), String>
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.