Struct glyph_brush::GlyphCalculator
source · pub struct GlyphCalculator<F = FontArc, X = Extra, H = DefaultSectionHasher> { /* private fields */ }
Expand description
Cut down version of a GlyphBrush
that can calculate pixel bounds,
but is unable to actually render anything.
Build using a GlyphCalculatorBuilder
.
Example
use glyph_brush::{ab_glyph::FontArc, GlyphCalculatorBuilder, GlyphCruncher, Section, Text};
let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf")).unwrap();
let glyphs = GlyphCalculatorBuilder::using_font(dejavu).build();
let section = Section::default().add_text(Text::new("Hello glyph_brush"));
// create the scope, equivalent to a lock on the cache when
// dropped will clean unused cached calculations like a draw call
let mut scope = glyphs.cache_scope();
let bounds = scope.glyph_bounds(section);
Caching behaviour
Calls to GlyphCalculatorGuard::glyph_bounds
,
GlyphCalculatorGuard::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.
Unlike a GlyphBrush
there is no concept of actually drawing
the section to imply when a section is used / no longer used. Instead a GlyphCalculatorGuard
is created, that provides the calculation functionality. Dropping indicates the ‘cache frame’
is over, similar to when a GlyphBrush
draws. Section calculations are cached for the next
‘cache frame’, if not used then they will be dropped.