Struct glyph_brush::GlyphBrushBuilder
source · pub struct GlyphBrushBuilder<'a, H = BuildHasherDefault<SeaHasher>> {
pub font_data: Vec<Font<'a>>,
pub initial_cache_size: (u32, u32),
pub gpu_cache_scale_tolerance: f32,
pub gpu_cache_position_tolerance: f32,
pub cache_glyph_positioning: bool,
pub cache_glyph_drawing: bool,
pub section_hasher: H,
}
Expand description
Builder for a GlyphBrush
.
Example
use glyph_brush::GlyphBrushBuilder;
let dejavu: &[u8] = include_bytes!("../../../fonts/DejaVuSans.ttf");
let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(dejavu).build();
Fields
font_data: Vec<Font<'a>>
initial_cache_size: (u32, u32)
gpu_cache_scale_tolerance: f32
gpu_cache_position_tolerance: f32
cache_glyph_positioning: bool
cache_glyph_drawing: bool
section_hasher: H
Implementations
sourceimpl<'a> GlyphBrushBuilder<'a>
impl<'a> GlyphBrushBuilder<'a>
sourcepub fn using_font_bytes<B: Into<SharedBytes<'a>>>(font_0_data: B) -> Self
pub fn using_font_bytes<B: Into<SharedBytes<'a>>>(font_0_data: B) -> Self
Specifies the default font data used to render glyphs.
Referenced with FontId(0)
, which is default.
pub fn using_fonts_bytes<B, V>(font_data: V) -> Selfwhere
B: Into<SharedBytes<'a>>,
V: Into<Vec<B>>,
sourcepub fn using_font(font_0: Font<'a>) -> Self
pub fn using_font(font_0: Font<'a>) -> Self
Specifies the default font used to render glyphs.
Referenced with FontId(0)
, which is default.
pub fn using_fonts<V: Into<Vec<Font<'a>>>>(fonts: V) -> Self
sourceimpl<'a, H: BuildHasher> GlyphBrushBuilder<'a, H>
impl<'a, H: BuildHasher> GlyphBrushBuilder<'a, H>
sourcepub fn add_font_bytes<B: Into<SharedBytes<'a>>>(
&mut self,
font_data: B
) -> FontId
pub fn add_font_bytes<B: Into<SharedBytes<'a>>>(
&mut self,
font_data: B
) -> FontId
Adds additional fonts to the one added in using_font
/
using_font_bytes
.
Returns a FontId
to reference this font.
sourcepub fn add_font(&mut self, font_data: Font<'a>) -> FontId
pub fn add_font(&mut self, font_data: Font<'a>) -> FontId
Adds additional fonts to the one added in using_font
/
using_font_bytes
.
Returns a FontId
to reference this font.
sourcepub fn initial_cache_size(self, size: (u32, u32)) -> Self
pub fn initial_cache_size(self, size: (u32, u32)) -> Self
Initial size of 2D texture used as a gpu cache, pixels (width, height). The GPU cache will dynamically quadruple in size whenever the current size is insufficient.
Defaults to (256, 256)
sourcepub fn gpu_cache_scale_tolerance(self, tolerance: f32) -> Self
pub fn gpu_cache_scale_tolerance(self, tolerance: f32) -> Self
Sets the maximum allowed difference in scale used for judging whether to reuse an existing glyph in the GPU cache.
Defaults to 0.5
See rusttype docs for rusttype::gpu_cache::Cache
sourcepub fn gpu_cache_position_tolerance(self, tolerance: f32) -> Self
pub fn gpu_cache_position_tolerance(self, tolerance: f32) -> Self
Sets the maximum allowed difference in subpixel position used for judging whether to reuse an existing glyph in the GPU cache. Anything greater than or equal to 1.0 means “don’t care”.
Defaults to 0.1
See rusttype docs for rusttype::gpu_cache::Cache
sourcepub fn cache_glyph_positioning(self, cache: bool) -> Self
pub fn cache_glyph_positioning(self, cache: bool) -> Self
Sets whether perform the calculation of glyph positioning according to the layout
every time, or use a cached result if the input Section
and GlyphPositioner
are the
same hash as a previous call.
Improves performance. Should only disable if using a custom GlyphPositioner that is
impure according to it’s inputs, so caching a previous call is not desired. Disabling
also disables cache_glyph_drawing
.
Defaults to true
sourcepub fn cache_glyph_drawing(self, cache: bool) -> Self
pub fn cache_glyph_drawing(self, cache: bool) -> Self
Sets optimising drawing by reusing the last draw requesting an identical draw queue.
Improves performance. Is disabled if
cache_glyph_positioning
is disabled.
Defaults to true
sourcepub fn section_hasher<T: BuildHasher>(
self,
section_hasher: T
) -> GlyphBrushBuilder<'a, T>
pub fn section_hasher<T: BuildHasher>(
self,
section_hasher: T
) -> GlyphBrushBuilder<'a, T>
Sets the section hasher. GlyphBrush
cannot handle absolute section hash collisions
so use a good hash algorithm.
This hasher is used to distinguish sections, rather than for hashmap internal use.
Defaults to seahash.
Example
GlyphBrushBuilder::using_font_bytes(some_font)
.section_hasher(SomeOtherBuildHasher::default())
// ...
sourcepub fn build(self) -> GlyphBrush<'a, H>
pub fn build(self) -> GlyphBrush<'a, H>
Builds a GlyphBrush
using the input gfx factory