pub struct FontRenderer(/* private fields */);
Expand description
A FontRenderer pairs a font source (typically a VectorFont
or bitmap font) and a GPU cache
for efficient rendering
Instead of uploading glyphs to the GPU every time they’re drawn, this method allows for future draws to reference these glyphs multiple times.
Implementations§
Source§impl FontRenderer
impl FontRenderer
Sourcepub fn from_font(gfx: &Graphics, source: Box<dyn FontProvider>) -> Result<Self>
pub fn from_font(gfx: &Graphics, source: Box<dyn FontProvider>) -> Result<Self>
Create a font from an arbitrary FontProvider
If you want to load a TTF file, consider VectorFont::load
and VectorFont::to_renderer
instead.
Sourcepub fn draw(
&mut self,
gfx: &mut Graphics,
text: &str,
color: Color,
offset: Vector,
) -> Result<Vector>
pub fn draw( &mut self, gfx: &mut Graphics, text: &str, color: Color, offset: Vector, ) -> Result<Vector>
Draw some text to the screen with a given color at a given position, returning the text extents
This method will not wrap but will respect newlines. To wrap, use
FontRenderer::draw_wrapping
. The returned value is how far the text extended past the
offset, e.g. the furthest right and furthest down position.
Sourcepub fn draw_wrapping(
&mut self,
gfx: &mut Graphics,
text: &str,
max_width: Option<f32>,
color: Color,
offset: Vector,
) -> Result<Vector>
pub fn draw_wrapping( &mut self, gfx: &mut Graphics, text: &str, max_width: Option<f32>, color: Color, offset: Vector, ) -> Result<Vector>
Draw some text to the screen with a given color at a given position, returning the text extents
If a maximum width is provided, the text will not extend beyond it. If a word encounters the maximum width, it will be wrapped down to a newline. The returned value is how far the text extended past the offset, e.g. the furthest right and furthest down position.
Sourcepub fn layout_glyphs(
&mut self,
gfx: &mut Graphics,
text: &str,
max_width: Option<f32>,
callback: impl FnMut(&mut Graphics, LayoutGlyph),
) -> Result<Vector>
pub fn layout_glyphs( &mut self, gfx: &mut Graphics, text: &str, max_width: Option<f32>, callback: impl FnMut(&mut Graphics, LayoutGlyph), ) -> Result<Vector>
Lay out the given text at a given font size, with a given maximum width, returning its extents
Each glyph (and the font) is passed into the callback as it is layed out, giving the option to render right away, examine and move on, etc.