Struct glyph_brush::GlyphBrush

source ·
pub struct GlyphBrush<'font, H = BuildHasherDefault<SeaHasher>> { /* private fields */ }
Expand description

Object allowing glyph drawing, containing cache state. Manages glyph positioning cacheing, glyph draw caching & efficient GPU texture cache updating.

Build using a GlyphBrushBuilder.

Caching behaviour

Calls to GlyphBrush::queue, GlyphBrush::pixel_bounds, GlyphBrush::glyphs calculate the positioned glyphs for a section. This is cached so future calls to any of the methods for the same section are much cheaper. In the case of GlyphBrush::queue the calculations will also be used for actual drawing.

The cache for a section will be cleared after a GlyphBrush::process_queued call when that section has not been used since the previous call.

Implementations

Queues a section/layout to be processed by the next call of process_queued. Can be called multiple times to queue multiple sections for drawing.

Used to provide custom GlyphPositioner logic, if using built-in Layout simply use queue

Benefits from caching, see caching behaviour.

Queues a section/layout to be processed by the next call of process_queued. Can be called multiple times to queue multiple sections for drawing.

Benefits from caching, see caching behaviour.

Processes all queued sections, calling texture update logic when necessary & returning a BrushAction. See queue.

Trims the cache, see caching behaviour.

glyph_brush.process_queued(
    (1024, 768),
    |rect, tex_data| update_texture(rect, tex_data),
    |vertex_data| into_vertex(vertex_data),
)?

Rebuilds the texture cache with new dimensions. Should be avoided if possible.

Example
glyph_brush.resize_texture(512, 512);

Returns the texture cache pixel dimensions (width, height).

Returns the available fonts.

The FontId corresponds to the index of the font data.

Adds an additional font to the one(s) initially added on build.

Returns a new FontId to reference this font.

Example
extern crate glyph_brush;
use glyph_brush::{GlyphBrushBuilder, Section};

// dejavu is built as default `FontId(0)`
let dejavu: &[u8] = include_bytes!("../../fonts/DejaVuSans.ttf");
let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(dejavu).build();

// some time later, add another font referenced by a new `FontId`
let open_sans_italic: &[u8] = include_bytes!("../../fonts/OpenSans-Italic.ttf");
let open_sans_italic_id = glyph_brush.add_font_bytes(open_sans_italic);

Adds an additional font to the one(s) initially added on build.

Returns a new FontId to reference this font.

Retains the section in the cache as if it had been used in the last draw-frame.

Should not generally be necessary, see caching behaviour.

Retains the section in the cache as if it had been used in the last draw-frame.

Should not generally be necessary, see caching behaviour.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the pixel bounding box for the input section using a custom layout. The box is a conservative whole number pixel rectangle that can contain the section. Read more
Returns an iterator over the PositionedGlyphs of the given section with a custom layout. Read more
Returns the pixel bounding box for the input section. The box is a conservative whole number pixel rectangle that can contain the section. Read more
Returns an iterator over the PositionedGlyphs of the given section. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.