Struct gfx_glyph::GlyphBrush
source · pub struct GlyphBrush<R: Resources, GF: Factory<R>, F = FontArc, 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
use gfx_glyph::{Section, Text};
let section = Section::default().add_text(Text::new("Hello gfx_glyph"));
glyph_brush.queue(section);
glyph_brush.queue(some_other_section);
glyph_brush.use_queue().draw(&mut gfx_encoder, &gfx_color)?;
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
.use_queue().draw(..)
call when that section has not been used since
the previous draw call.
Implementations§
source§impl<R, GF, F, H> GlyphBrush<R, GF, F, H>where
R: Resources,
GF: Factory<R>,
H: BuildHasher,
F: Font,
impl<R, GF, F, H> GlyphBrush<R, GF, F, H>where R: Resources, GF: Factory<R>, H: BuildHasher, F: Font,
source§impl<R, GF, F, H> GlyphBrush<R, GF, F, H>where
F: Font + Sync,
R: Resources,
GF: Factory<R>,
H: BuildHasher,
impl<R, GF, F, H> GlyphBrush<R, GF, F, H>where F: Font + Sync, R: Resources, GF: Factory<R>, H: BuildHasher,
sourcepub fn queue<'a, S>(&mut self, section: S)where
S: Into<Cow<'a, Section<'a>>>,
pub fn queue<'a, S>(&mut self, section: S)where S: Into<Cow<'a, Section<'a>>>,
Queues a section/layout to be drawn by the next call of
.use_queue().draw(..)
. Can be called multiple times
to queue multiple sections for drawing.
Benefits from caching, see caching behaviour.
sourcepub fn use_queue(&mut self) -> DrawBuilder<'_, F, R, GF, H, ()>
pub fn use_queue(&mut self) -> DrawBuilder<'_, F, R, GF, H, ()>
Returns a DrawBuilder
allowing the queued glyphs to be drawn.
Drawing will trim the cache, see caching behaviour.
Example
glyph_brush.use_queue().draw(&mut gfx_encoder, &gfx_color)?;
sourcepub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G)where
G: GlyphPositioner,
S: Into<Cow<'a, Section<'a>>>,
pub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G)where G: GlyphPositioner, S: Into<Cow<'a, Section<'a>>>,
Queues a section/layout to be drawn by the next call of
.use_queue().draw(..)
. 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_pre_positioned(
&mut self,
glyphs: Vec<SectionGlyph>,
extra: Vec<Extra>,
bounds: Rect
)
pub fn queue_pre_positioned( &mut self, glyphs: Vec<SectionGlyph>, extra: Vec<Extra>, bounds: Rect )
Queues pre-positioned glyphs to be processed by the next call of
.use_queue().draw(..)
. Can be called multiple times.
sourcepub fn keep_cached_custom_layout<'a, S, G>(
&mut self,
section: S,
custom_layout: &G
)where
S: Into<Cow<'a, Section<'a>>>,
G: GlyphPositioner,
pub fn keep_cached_custom_layout<'a, S, G>( &mut self, section: S, custom_layout: &G )where S: Into<Cow<'a, Section<'a>>>, G: GlyphPositioner,
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.
sourcepub fn keep_cached<'a, S>(&mut self, section: S)where
S: Into<Cow<'a, Section<'a>>>,
pub fn keep_cached<'a, S>(&mut self, section: S)where S: Into<Cow<'a, Section<'a>>>,
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.
Trait Implementations§
source§impl<R, GF, F, H> GlyphCruncher<F, Extra> for GlyphBrush<R, GF, F, H>where
F: Font,
R: Resources,
GF: Factory<R>,
H: BuildHasher,
impl<R, GF, F, H> GlyphCruncher<F, Extra> for GlyphBrush<R, GF, F, H>where F: Font, R: Resources, GF: Factory<R>, H: BuildHasher,
source§fn glyphs_custom_layout<'a, 'b, S, L>(
&'b mut self,
section: S,
custom_layout: &L
) -> SectionGlyphIter<'b>where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, Section<'a>>>,
fn glyphs_custom_layout<'a, 'b, S, L>( &'b mut self, section: S, custom_layout: &L ) -> SectionGlyphIter<'b>where L: GlyphPositioner + Hash, S: Into<Cow<'a, Section<'a>>>,
PositionedGlyph
s of the given section with a custom layout. Read more