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

Cut down version of a GlyphBrush that can calculate pixel bounds, but is unable to actually render anything.

Build using a GlyphCalculatorBuilder.

Example

use glyph_brush::{ab_glyph::FontArc, GlyphCalculatorBuilder, GlyphCruncher, Section, Text};

let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf")).unwrap();
let glyphs = GlyphCalculatorBuilder::using_font(dejavu).build();

let section = Section::default().add_text(Text::new("Hello glyph_brush"));

// create the scope, equivalent to a lock on the cache when
// dropped will clean unused cached calculations like a draw call
let mut scope = glyphs.cache_scope();

let bounds = scope.glyph_bounds(section);

Caching behaviour

Calls to GlyphCalculatorGuard::glyph_bounds, GlyphCalculatorGuard::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.

Unlike a GlyphBrush there is no concept of actually drawing the section to imply when a section is used / no longer used. Instead a GlyphCalculatorGuard is created, that provides the calculation functionality. Dropping indicates the ‘cache frame’ is over, similar to when a GlyphBrush draws. Section calculations are cached for the next ‘cache frame’, if not used then they will be dropped.

Implementations§

source§

impl<F: Font, X, H: BuildHasher + Clone> GlyphCalculator<F, X, H>

source

pub fn cache_scope(&self) -> GlyphCalculatorGuard<'_, F, X, H>

source

pub fn fonts(&self) -> &[F]

Returns the available fonts.

The FontId corresponds to the index of the font data.

Trait Implementations§

source§

impl<F, X, H> Debug for GlyphCalculator<F, X, H>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F, X, H> RefUnwindSafe for GlyphCalculator<F, X, H>where F: RefUnwindSafe, H: RefUnwindSafe,

§

impl<F, X, H> Send for GlyphCalculator<F, X, H>where F: Send, H: Send, X: Send,

§

impl<F, X, H> Sync for GlyphCalculator<F, X, H>where F: Sync, H: Sync, X: Send,

§

impl<F, X, H> Unpin for GlyphCalculator<F, X, H>where F: Unpin, H: Unpin, X: Unpin,

§

impl<F, X, H> UnwindSafe for GlyphCalculator<F, X, 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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 = _

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.
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.
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