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
sourceimpl<'font, H: BuildHasher> GlyphBrush<'font, H>
impl<'font, H: BuildHasher> GlyphBrush<'font, H>
sourcepub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G)where
G: GlyphPositioner,
S: Into<Cow<'a, VariedSection<'a>>>,
pub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G)where
G: GlyphPositioner,
S: Into<Cow<'a, VariedSection<'a>>>,
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.
sourcepub fn queue<'a, S>(&mut self, section: S)where
S: Into<Cow<'a, VariedSection<'a>>>,
pub fn queue<'a, S>(&mut self, section: S)where
S: Into<Cow<'a, VariedSection<'a>>>,
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.
sourcepub fn process_queued<V, F1, F2>(
&mut self,
(screen_w, screen_h): (u32, u32),
update_texture: F1,
to_vertex: F2
) -> Result<BrushAction<V>, BrushError>where
F1: FnMut(Rect<u32>, &[u8]),
F2: Fn(GlyphVertex) -> V,
pub fn process_queued<V, F1, F2>(
&mut self,
(screen_w, screen_h): (u32, u32),
update_texture: F1,
to_vertex: F2
) -> Result<BrushAction<V>, BrushError>where
F1: FnMut(Rect<u32>, &[u8]),
F2: Fn(GlyphVertex) -> V,
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),
)?
sourcepub fn resize_texture(&mut self, new_width: u32, new_height: u32)
pub fn resize_texture(&mut self, new_width: u32, new_height: u32)
Rebuilds the texture cache with new dimensions. Should be avoided if possible.
Example
glyph_brush.resize_texture(512, 512);
sourcepub fn texture_dimensions(&self) -> (u32, u32)
pub fn texture_dimensions(&self) -> (u32, u32)
Returns the texture cache pixel dimensions (width, height)
.
sourcepub fn fonts(&self) -> &[Font<'font>]
pub fn fonts(&self) -> &[Font<'font>]
Returns the available fonts.
The FontId
corresponds to the index of the font data.
sourcepub fn add_font_bytes<'a: 'font, B: Into<SharedBytes<'a>>>(
&mut self,
font_data: B
) -> FontId
pub fn add_font_bytes<'a: 'font, B: Into<SharedBytes<'a>>>(
&mut self,
font_data: B
) -> FontId
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);
Trait Implementations
sourceimpl<'font, H> Debug for GlyphBrush<'font, H>
impl<'font, H> Debug for GlyphBrush<'font, H>
sourceimpl<'font, H: BuildHasher> GlyphCruncher<'font> for GlyphBrush<'font, H>
impl<'font, H: BuildHasher> GlyphCruncher<'font> for GlyphBrush<'font, H>
sourcefn pixel_bounds_custom_layout<'a, S, L>(
&mut self,
section: S,
custom_layout: &L
) -> Option<Rect<i32>>where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
fn pixel_bounds_custom_layout<'a, S, L>(
&mut self,
section: S,
custom_layout: &L
) -> Option<Rect<i32>>where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
sourcefn glyphs_custom_layout<'a, 'b, S, L>(
&'b mut self,
section: S,
custom_layout: &L
) -> PositionedGlyphIter<'b, 'font>where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
fn glyphs_custom_layout<'a, 'b, S, L>(
&'b mut self,
section: S,
custom_layout: &L
) -> PositionedGlyphIter<'b, 'font>where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
PositionedGlyph
s of the given section with a custom layout. Read moresourcefn pixel_bounds<'a, S>(&mut self, section: S) -> Option<Rect<i32>>where
S: Into<Cow<'a, VariedSection<'a>>>,
fn pixel_bounds<'a, S>(&mut self, section: S) -> Option<Rect<i32>>where
S: Into<Cow<'a, VariedSection<'a>>>,
sourcefn glyphs<'a, 'b, S>(&'b mut self, section: S) -> PositionedGlyphIter<'b, 'font>where
S: Into<Cow<'a, VariedSection<'a>>>,
fn glyphs<'a, 'b, S>(&'b mut self, section: S) -> PositionedGlyphIter<'b, 'font>where
S: Into<Cow<'a, VariedSection<'a>>>,
PositionedGlyph
s of the given section. Read more