Struct ggez::graphics::GlyphBrush[][src]

pub struct GlyphBrush<V, X = Extra, F = FontArc, H = RandomXxHashBuilder64> { /* fields omitted */ }
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.

Also see GlyphCruncher trait which providers extra functionality, such as glyph_bounds.

Caching behaviour

Calls to GlyphBrush::queue, GlyphBrush::glyph_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.

Texture caching behaviour

Note the gpu/draw cache may contain multiple versions of the same glyph at different subpixel positions. This is required for high quality text as a glyph’s positioning is always exactly aligned to it’s draw positioning.

This behaviour can be adjusted with GlyphBrushBuilder::draw_cache_position_tolerance (struct.GlyphBrushBuilder.html#method.draw_cache_position_tolerance).

Implementations

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

Returns a new FontId to reference this font.

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.

glyph_brush.queue(Section::default().add_text(Text::new("Hello glyph_brush")));

Queues pre-positioned glyphs to be processed by the next call of process_queued. Can be called multiple times.

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

Example
glyph_brush.resize_texture(512, 512);

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

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.

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

Two closures are required:

  • update_texture is called when new glyph texture data has been drawn for update in the actual texture. The arguments are the rect position of the data in the texture & the byte data itself which is a single u8 alpha value per pixel.
  • to_vertex maps a single glyph’s GlyphVertex data into a generic vertex type. The mapped vertices are returned in an Ok(BrushAction::Draw(vertices)) result. It’s recommended to use a single vertex per glyph quad for best performance.

Trims the cache, see caching behaviour.

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

Returns true if this glyph is currently present in the draw cache texture.

So false means either this glyph is invisible, like ' ', or hasn’t been queued & processed yet.

Return a GlyphBrushBuilder prefilled with the properties of this GlyphBrush.

Example
let glyph_brush: GlyphBrush<Vertex> = GlyphBrushBuilder::using_font(sans)
    .initial_cache_size((128, 128))
    .build();

let new_brush: GlyphBrush<Vertex> = glyph_brush.to_builder().build();
assert_eq!(new_brush.texture_dimensions(), (128, 128));

Trait Implementations

Formats the value using the given formatter. Read more

Returns an iterator over the PositionedGlyphs of the given section with a custom layout. Read more

Returns a bounding box for the section glyphs calculated using each glyph’s vertical & horizontal metrics. Read more

Returns the available fonts. Read more

Returns an iterator over the PositionedGlyphs of the given section. Read more

Returns a bounding box for the section glyphs calculated using each glyph’s vertical & horizontal metrics. 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

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

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.