Struct gfx_glyph::GlyphBrush

source ·
pub struct GlyphBrush<'font, R: Resources, F: Factory<R>, H = DefaultSectionHasher> { /* private fields */ }
Expand description

Object allowing glyph drawing, containing cache state. Manages glyph positioning cacheing, glyph draw caching & efficient GPU texture cache updating and re-sizing on demand.

Build using a GlyphBrushBuilder.

Example

extern crate gfx_glyph;
use gfx_glyph::Section;

let section = Section {
    text: "Hello gfx_glyph",
    ..Section::default()
};

glyph_brush.queue(section);
glyph_brush.queue(some_other_section);

glyph_brush.draw_queued(&mut gfx_encoder, &gfx_color, &gfx_depth)?;

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::draw_queued call when that section has not been used since the previous draw call.

Implementations

Queues a section/layout to be drawn by the next call of draw_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 drawn by the next call of draw_queued. Can be called multiple times to queue multiple sections for drawing.

Benefits from caching, see caching behaviour.

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

Should not be necessary unless using multiple draws per frame with distinct transforms, see caching behaviour.

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

Should not be necessary unless using multiple draws per frame with distinct transforms, see caching behaviour.

Draws all queued sections onto a render target, applying a position transform (e.g. a projection). See queue.

Trims the cache, see caching behaviour.

Raw usage

Can also be used with gfx raw render & depth views if necessary. The Format must also be provided. See example.

Draws all queued sections onto a render target, applying a position transform (e.g. a projection). See queue.

Trims the cache, see caching behaviour.

Raw usage

Can also be used with gfx raw render & depth views if necessary. The Format must also be provided.

glyph_brush.draw_queued_with_transform(
    transform,
    &mut gfx_encoder,
    &(raw_render_view, format::Srgba8::get_format()),
    &(raw_depth_view, format::Depth::get_format()),
)?

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 gfx_glyph;
use gfx_glyph::{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(gfx_factory.clone());

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

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.