pub struct GlyphBrushBuilder<F = FontArc, H = DefaultSectionHasher> { /* private fields */ }
Expand description

Builder for a GlyphBrush.

Example

use gfx_glyph::{ab_glyph::FontArc, GlyphBrushBuilder};

let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf")).unwrap();
let mut glyph_brush = GlyphBrushBuilder::using_font(dejavu).build(gfx_factory.clone());

Implementations§

source§

impl GlyphBrushBuilder<()>

source

pub fn using_font<F: Font>(font_0: F) -> GlyphBrushBuilder<F>

Specifies the default font used to render glyphs. Referenced with FontId(0), which is default.

source

pub fn using_fonts<F: Font, V: Into<Vec<F>>>(fonts: V) -> GlyphBrushBuilder<F>

source

pub fn without_fonts() -> Self

Create a new builder without any fonts.

source§

impl<F, H> GlyphBrushBuilder<F, H>

source

pub fn replace_fonts<F2: Font, V, NF>( self, font_fn: NF ) -> GlyphBrushBuilder<F2, H>where V: Into<Vec<F2>>, NF: FnOnce(Vec<F>) -> V,

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. Or on a GlyphBrushBuilder<()> built using without_fonts().

source§

impl<F, H> GlyphBrushBuilder<F, H>where F: Font, H: BuildHasher,

source

pub fn add_font(&mut self, font_data: F) -> FontId

Adds additional fonts to the one added in using_font. Returns a FontId to reference this font.

source

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)

source

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

source

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

source

pub fn draw_cache_align_4x4(self, b: 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

source

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

source

pub fn cache_redraws(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

source

pub fn depth_test(self, depth_test: Depth) -> Self

Sets the depth test to use on the text section z values.

Defaults to: Only draw when the fragment’s output depth is less than or equal to the current depth buffer value, and update the buffer.

Example
GlyphBrushBuilder::using_font(some_font).depth_test(gfx::preset::depth::PASS_WRITE)
// ...
source

pub fn texture_filter_method(self, filter_method: FilterMethod) -> Self

Sets the texture filtering method.

Defaults to Bilinear

Example
GlyphBrushBuilder::using_font(some_font)
    .texture_filter_method(gfx::texture::FilterMethod::Scale)
// ...
source

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())
// ...
source

pub fn build<R, GF>(self, factory: GF) -> GlyphBrush<R, GF, F, H>where R: Resources, GF: Factory<R>,

Builds a GlyphBrush using the input gfx factory

Auto Trait Implementations§

§

impl<F, H> RefUnwindSafe for GlyphBrushBuilder<F, H>where F: RefUnwindSafe, H: RefUnwindSafe,

§

impl<F, H> Send for GlyphBrushBuilder<F, H>where F: Send, H: Send,

§

impl<F, H> Sync for GlyphBrushBuilder<F, H>where F: Sync, H: Sync,

§

impl<F, H> Unpin for GlyphBrushBuilder<F, H>where F: Unpin, H: Unpin,

§

impl<F, H> UnwindSafe for GlyphBrushBuilder<F, H>where F: UnwindSafe, H: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V