[][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 &'_ [u8]
pub fn fonts(&self) -> &[Font][src]

Returns the available fonts.

The FontId corresponds to the index of the font data.

pub fn draw_queued<C, CV, DV>(
    &mut self,
    encoder: &mut Encoder<R, C>,
    target: &CV,
    depth_target: &DV
) -> Result<(), String> where
    C: CommandBuffer<R>,
    CV: RawAndFormat<Raw = RawRenderTargetView<R>>,
    DV: RawAndFormat<Raw = RawDepthStencilView<R>>, 
[src]

Deprecated:

Use use_queue() to build draws.

Draws all queued sections onto a render target, applying the default transform.

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]

fn pixel_bounds<'a, S>(&mut self, section: S) -> Option<Rect<i32>> where
    S: Into<Cow<'a, VariedSection<'a>>>, 
[src]

Returns the pixel bounding box for the input section. The box is a conservative whole number pixel rectangle that can contain the section. Read more

fn glyphs<'a, S>(
    &'b mut self,
    section: S
) -> Map<Iter<'b, (PositionedGlyph<'font>, [f32; 4], FontId)>, fn(&'b (PositionedGlyph<'font>, [f32; 4], FontId)) -> &'b PositionedGlyph<'font>> where
    S: Into<Cow<'a, VariedSection<'a>>>, 
[src]

Returns an iterator over the PositionedGlyphs of the given section. Read more

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

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto 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 for T where
    T: ?Sized
[src]

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

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