#[non_exhaustive]pub struct GlyphBrushBuilder<F = FontArc, H = DefaultSectionHasher> {
pub font_data: Vec<F>,
pub cache_glyph_positioning: bool,
pub cache_redraws: bool,
pub section_hasher: H,
pub draw_cache_builder: DrawCacheBuilder,
}
Expand description
Builder for a GlyphBrush
.
§Example
use glyph_brush::{ab_glyph::FontArc, GlyphBrush, GlyphBrushBuilder};
let dejavu = FontArc::try_from_slice(include_bytes!("../../../fonts/DejaVuSans.ttf")).unwrap();
let mut glyph_brush: GlyphBrush<Vertex> = GlyphBrushBuilder::using_font(dejavu).build();
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.font_data: Vec<F>
§cache_glyph_positioning: bool
§cache_redraws: bool
§section_hasher: H
§draw_cache_builder: DrawCacheBuilder
Implementations§
source§impl GlyphBrushBuilder<()>
impl GlyphBrushBuilder<()>
sourcepub fn using_fonts<F: Font>(fonts: Vec<F>) -> GlyphBrushBuilder<F>
pub fn using_fonts<F: Font>(fonts: Vec<F>) -> GlyphBrushBuilder<F>
Create a new builder with multiple fonts.
sourcepub fn using_font<F: Font>(font: F) -> GlyphBrushBuilder<F>
pub fn using_font<F: Font>(font: F) -> GlyphBrushBuilder<F>
Create a new builder with multiple fonts.
sourcepub fn without_fonts() -> GlyphBrushBuilder<()>
pub fn without_fonts() -> GlyphBrushBuilder<()>
Create a new builder without any fonts.
source§impl<F, H> GlyphBrushBuilder<F, H>
impl<F, H> GlyphBrushBuilder<F, H>
sourcepub fn replace_fonts<F2: Font, V, NF>(
self,
font_fn: NF,
) -> GlyphBrushBuilder<F2, H>
pub fn replace_fonts<F2: Font, V, NF>( self, font_fn: NF, ) -> GlyphBrushBuilder<F2, H>
Consume all builder fonts a replace with new fonts returned by the input function.
Generally only makes sense when wanting to change fonts after calling
GlyphBrush::to_builder
.
§Example
let two_font_brush: GlyphBrush<Vertex>
= GlyphBrushBuilder::using_fonts(vec![open_sans, deja_vu_sans]).build();
let one_font_brush: GlyphBrush<FontRef<'static>, Vertex> = two_font_brush
.to_builder()
.replace_fonts(|mut fonts| {
// remove open_sans, leaving just deja_vu as FontId(0)
fonts.remove(0);
fonts
})
.build();
assert_eq!(one_font_brush.fonts().len(), 1);
assert_eq!(two_font_brush.fonts().len(), 2);
source§impl<F: Font, H: BuildHasher> GlyphBrushBuilder<F, H>
impl<F: Font, H: BuildHasher> GlyphBrushBuilder<F, H>
sourcepub fn add_font<I: Into<F>>(&mut self, font_data: I) -> FontId
pub fn add_font<I: Into<F>>(&mut self, font_data: I) -> FontId
Adds additional fonts to the one added in using_font
.
Returns a FontId
to reference this font.
sourcepub fn initial_cache_size(self, (w, h): (u32, u32)) -> Self
pub fn initial_cache_size(self, (w, h): (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 draw_cache_scale_tolerance(self, tolerance: f32) -> Self
pub fn draw_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 docs for glyph_brush_draw_cache::DrawCache
sourcepub fn draw_cache_position_tolerance(self, tolerance: f32) -> Self
pub fn draw_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 docs for glyph_brush_draw_cache::DrawCache
sourcepub fn multithread(self, multithread: bool) -> Self
pub fn multithread(self, multithread: bool) -> Self
When multiple CPU cores are available spread draw-cache work across all cores.
Defaults to true
.
sourcepub fn draw_cache_align_4x4(self, align: bool) -> Self
pub fn draw_cache_align_4x4(self, align: bool) -> Self
Align glyphs in texture cache to 4x4 texel boundaries.
If your backend requires texture updates to be aligned to 4x4 texel
boundaries (e.g. WebGL), this should be set to true
.
Defaults to false
See docs for glyph_brush_draw_cache::DrawCache
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_redraws
.
Defaults to true
sourcepub fn cache_redraws(self, cache_redraws: bool) -> Self
pub fn cache_redraws(self, cache_redraws: bool) -> Self
Sets optimising vertex drawing by reusing the last draw requesting an identical draw queue.
Will result in the usage of BrushAction::ReDraw
.
Improves performance. Is disabled if
cache_glyph_positioning
is disabled.
Defaults to true
sourcepub fn section_hasher<T: BuildHasher>(
self,
section_hasher: T,
) -> GlyphBrushBuilder<F, T>
pub fn section_hasher<T: BuildHasher>( self, section_hasher: T, ) -> GlyphBrushBuilder<F, 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 xxHash.
§Example
GlyphBrushBuilder::using_font(some_font)
.section_hasher(SomeOtherBuildHasher::default())
// ...
sourcepub fn build<V, X>(self) -> GlyphBrush<V, X, F, H>
pub fn build<V, X>(self) -> GlyphBrush<V, X, F, H>
Builds a GlyphBrush
.
If type inference fails try declaring the types V
& X
.
See GlyphBrush
generic types.
let glyph_brush = GlyphBrushBuilder::using_font(some_font)
.build::<Vertex, glyph_brush::Extra>();
sourcepub fn rebuild<V, X>(self, brush: &mut GlyphBrush<V, X, F, H>)
pub fn rebuild<V, X>(self, brush: &mut GlyphBrush<V, X, F, H>)
Rebuilds an existing GlyphBrush
with this builder’s properties. This will clear all
caches and queues.
§Example
let mut glyph_brush: GlyphBrush<Vertex> = GlyphBrushBuilder::using_font(sans).build();
assert_eq!(glyph_brush.texture_dimensions(), (256, 256));
// Use a new builder to rebuild the brush with a smaller initial cache size
glyph_brush.to_builder().initial_cache_size((64, 64)).rebuild(&mut glyph_brush);
assert_eq!(glyph_brush.texture_dimensions(), (64, 64));
Auto Trait Implementations§
impl<F, H> Freeze for GlyphBrushBuilder<F, H>where
H: Freeze,
impl<F, H> RefUnwindSafe for GlyphBrushBuilder<F, H>where
H: RefUnwindSafe,
F: RefUnwindSafe,
impl<F, H> Send for GlyphBrushBuilder<F, H>
impl<F, H> Sync for GlyphBrushBuilder<F, H>
impl<F, H> Unpin for GlyphBrushBuilder<F, H>
impl<F, H> UnwindSafe for GlyphBrushBuilder<F, H>where
H: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more