glyph_brush

Trait GlyphCruncher

source
pub trait GlyphCruncher<F: Font = FontArc, X: Clone = Extra> {
    // Required methods
    fn glyphs_custom_layout<'a, 'b, S, L>(
        &'b mut self,
        section: S,
        custom_layout: &L,
    ) -> SectionGlyphIter<'b>
       where X: 'a,
             L: GlyphPositioner + Hash,
             S: Into<Cow<'a, Section<'a, X>>>;
    fn fonts(&self) -> &[F];
    fn glyph_bounds_custom_layout<'a, S, L>(
        &mut self,
        section: S,
        custom_layout: &L,
    ) -> Option<Rect>
       where X: 'a,
             L: GlyphPositioner + Hash,
             S: Into<Cow<'a, Section<'a, X>>>;

    // Provided methods
    fn glyphs<'a, 'b, S>(&'b mut self, section: S) -> SectionGlyphIter<'b>
       where X: 'a,
             S: Into<Cow<'a, Section<'a, X>>> { ... }
    fn glyph_bounds<'a, S>(&mut self, section: S) -> Option<Rect>
       where X: 'a,
             S: Into<Cow<'a, Section<'a, X>>> { ... }
}
Expand description

Common glyph layout logic.

§Example

use glyph_brush::GlyphCruncher;

let default_font = glyph_brush.fonts()[0];

Required Methods§

source

fn glyphs_custom_layout<'a, 'b, S, L>( &'b mut self, section: S, custom_layout: &L, ) -> SectionGlyphIter<'b>
where X: 'a, L: GlyphPositioner + Hash, S: Into<Cow<'a, Section<'a, X>>>,

Returns an iterator over the positioned SectionGlyphs of the given section with a custom layout.

Benefits from caching, see caching behaviour.

source

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

Returns the available fonts.

The FontId corresponds to the index of the font data.

source

fn glyph_bounds_custom_layout<'a, S, L>( &mut self, section: S, custom_layout: &L, ) -> Option<Rect>
where X: 'a, L: GlyphPositioner + Hash, S: Into<Cow<'a, Section<'a, X>>>,

Returns a bounding box for the section glyphs calculated using each glyph’s vertical & horizontal metrics.

If the section is empty the call will return None.

The bounds will always lay within the specified layout bounds, ie that returned by the layout’s bounds_rect function.

Benefits from caching, see caching behaviour.

Provided Methods§

source

fn glyphs<'a, 'b, S>(&'b mut self, section: S) -> SectionGlyphIter<'b>
where X: 'a, S: Into<Cow<'a, Section<'a, X>>>,

Returns an iterator over the positioned SectionGlyphs of the given section.

Benefits from caching, see caching behaviour.

§Example

Use section_index & byte_index to lookup the source Section::text & char from which a positioned glyph was derived.

let section = Section::default()
    .add_text(Text::new("it").with_color([0.3, 0.3, 0.9, 1.0]))
    .add_text(Text::new("s").with_color([0.9, 0.3, 0.3, 1.0]));

for g in glyph_brush.glyphs(&section) {
    let txt = section.text[g.section_index];
    let char = txt.text[g.byte_index..].chars().next().unwrap();
    println!("'{char}' {:?} color={:?}", g.glyph.id, txt.extra.color);
}
// prints:
// 'i' GlyphId(76) color=[0.3, 0.3, 0.9, 1.0]
// 't' GlyphId(87) color=[0.3, 0.3, 0.9, 1.0]
// 's' GlyphId(86) color=[0.9, 0.3, 0.3, 1.0]
source

fn glyph_bounds<'a, S>(&mut self, section: S) -> Option<Rect>
where X: 'a, S: Into<Cow<'a, Section<'a, X>>>,

Returns a bounding box for the section glyphs calculated using each glyph’s vertical & horizontal metrics.

If the section is empty the call will return None.

The bounds will always lay within the specified layout bounds, ie that returned by the layout’s bounds_rect function.

Benefits from caching, see caching behaviour.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

source§

impl<F, V, X, H> GlyphCruncher<F, X> for GlyphBrush<V, X, F, H>
where X: Clone + Hash, F: Font, V: Clone + 'static, H: BuildHasher,

source§

impl<F: Font, X: Clone + Hash, H: BuildHasher> GlyphCruncher<F, X> for GlyphCalculatorGuard<'_, F, X, H>