[][src]Struct gfx_glyph::GlyphBrush

pub struct GlyphBrush<'font, R: Resources, F: Factory<R>, H = DefaultSectionHasher> { /* fields omitted */ }

Object allowing glyph drawing, containing cache state. Manages glyph positioning cacheing, glyph draw caching & efficient GPU texture cache updating and re-sizing on demand.

Build using a GlyphBrushBuilder.

Example

use gfx_glyph::Section;

let section = Section {
    text: "Hello gfx_glyph",
    ..Section::default()
};

glyph_brush.queue(section);
glyph_brush.queue(some_other_section);

glyph_brush.use_queue().draw(&mut gfx_encoder, &gfx_color)?;

Caching behaviour

Calls to GlyphBrush::queue, GlyphBrush::pixel_bounds, GlyphBrush::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. In the case of GlyphBrush::queue the calculations will also be used for actual drawing.

The cache for a section will be cleared after a .use_queue().draw(..) call when that section has not been used since the previous draw call.

Methods

impl<'font, R: Resources, F: Factory<R>, H: BuildHasher> GlyphBrush<'font, R, F, H>[src]

pub fn queue<'a, S>(&mut self, section: S) where
    S: Into<Cow<'a, VariedSection<'a>>>, 
[src]

Queues a section/layout to be drawn by the next call of .use_queue().draw(..). Can be called multiple times to queue multiple sections for drawing.

Benefits from caching, see caching behaviour.

pub fn use_queue(&mut self) -> DrawBuilder<'_, 'font, R, F, H, ()>[src]

Returns a DrawBuilder allowing the queued glyphs to be drawn.

Drawing will trim the cache, see caching behaviour.

Example

glyph_brush.use_queue().draw(&mut gfx_encoder, &gfx_color)?;

pub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G) where
    G: GlyphPositioner,
    S: Into<Cow<'a, VariedSection<'a>>>, 
[src]

Queues a section/layout to be drawn by the next call of .use_queue().draw(..). Can be called multiple times to queue multiple sections for drawing.

Used to provide custom GlyphPositioner logic, if using built-in Layout simply use queue

Benefits from caching, see caching behaviour.

pub fn queue_pre_positioned(
    &mut self,
    glyphs: Vec<(PositionedGlyph<'font>, Color, FontId)>,
    bounds: Rect<f32>,
    z: f32
)
[src]

Queues pre-positioned glyphs to be processed by the next call of .use_queue().draw(..). Can be called multiple times.

pub fn keep_cached_custom_layout<'a, S, G>(
    &mut self,
    section: S,
    custom_layout: &G
) where
    S: Into<Cow<'a, VariedSection<'a>>>,
    G: GlyphPositioner
[src]

Retains the section in the cache as if it had been used in the last draw-frame.

Should not be necessary unless using multiple draws per frame with distinct transforms, see caching behaviour.

pub fn keep_cached<'a, S>(&mut self, section: S) where
    S: Into<Cow<'a, VariedSection<'a>>>, 
[src]

Retains the section in the cache as if it had been used in the last draw-frame.

Should not be necessary unless using multiple draws per frame with distinct transforms, see caching behaviour.

Important traits for &'_ mut [u8]
pub fn fonts(&self) -> &[Font][src]

Returns the available fonts.

The FontId corresponds to the index of the font data.

pub fn add_font_bytes<'a: 'font, B: Into<SharedBytes<'a>>>(
    &mut self,
    font_data: B
) -> FontId
[src]

Adds an additional font to the one(s) initially added on build.

Returns a new FontId to reference this font.

Example

use gfx_glyph::{GlyphBrushBuilder, Section};

// dejavu is built as default `FontId(0)`
let dejavu: &[u8] = include_bytes!("../../fonts/DejaVuSans.ttf");
let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(dejavu).build(gfx_factory.clone());

// some time later, add another font referenced by a new `FontId`
let open_sans_italic: &[u8] = include_bytes!("../../fonts/OpenSans-Italic.ttf");
let open_sans_italic_id = glyph_brush.add_font_bytes(open_sans_italic);

pub fn add_font<'a: 'font>(&mut self, font_data: Font<'a>) -> FontId[src]

Adds an additional font to the one(s) initially added on build.

Returns a new FontId to reference this font.

Trait Implementations

impl<'_, R: Resources, F: Factory<R>, H> Debug for GlyphBrush<'_, R, F, H>[src]

impl<'font, R: Resources, F: Factory<R>, H: BuildHasher> GlyphCruncher<'font> for GlyphBrush<'font, R, F, H>[src]

Auto Trait Implementations

impl<'font, R, F, H> Send for GlyphBrush<'font, R, F, H> where
    F: Send,
    H: Send,
    <R as Resources>::Buffer: Send + Sync,
    <R as Resources>::DepthStencilView: Send + Sync,
    <R as Resources>::Mapping: Send,
    <R as Resources>::PipelineStateObject: Send + Sync,
    <R as Resources>::Program: Send + Sync,
    <R as Resources>::RenderTargetView: Send + Sync,
    <R as Resources>::Sampler: Send + Sync,
    <R as Resources>::ShaderResourceView: Send + Sync,
    <R as Resources>::Texture: Send + Sync

impl<'font, R, F, H> Sync for GlyphBrush<'font, R, F, H> where
    F: Sync,
    H: Sync,
    <R as Resources>::Buffer: Send + Sync,
    <R as Resources>::DepthStencilView: Send + Sync,
    <R as Resources>::Mapping: Send,
    <R as Resources>::PipelineStateObject: Send + Sync,
    <R as Resources>::Program: Send + Sync,
    <R as Resources>::RenderTargetView: Send + Sync,
    <R as Resources>::Sampler: Send + Sync,
    <R as Resources>::ShaderResourceView: Send + Sync,
    <R as Resources>::Texture: Send + Sync

impl<'font, R, F, H> Unpin for GlyphBrush<'font, R, F, H> where
    F: Unpin,
    H: Unpin

impl<'font, R, F, H = RandomXxHashBuilder64> !UnwindSafe for GlyphBrush<'font, R, F, H>

impl<'font, R, F, H = RandomXxHashBuilder64> !RefUnwindSafe for GlyphBrush<'font, R, F, H>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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