[−][src]Struct glyph_brush::GlyphBrush
Object allowing glyph drawing, containing cache state. Manages glyph positioning cacheing, glyph draw caching & efficient GPU texture cache updating.
Build using a GlyphBrushBuilder
.
Also see GlyphCruncher
trait which providers extra functionality,
such as glyph_bounds
.
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
GlyphBrush::process_queued
call when that section has not been used
since the previous call.
Texture caching behaviour
Note the gpu/draw cache may contain multiple versions of the same glyph at different subpixel positions. This is required for high quality text as a glyph's positioning is always exactly aligned to it's draw positioning.
This behaviour can be adjusted with
GlyphBrushBuilder::gpu_cache_position_tolerance
(struct.GlyphBrushBuilder.html#method.gpu_cache_position_tolerance).
Methods
impl<'font, V, H> GlyphBrush<'font, V, H> where
V: Clone + 'static,
H: BuildHasher,
[src]
V: Clone + 'static,
H: BuildHasher,
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]
G: GlyphPositioner,
S: Into<Cow<'a, VariedSection<'a>>>,
Queues a section/layout to be processed by the next call of
process_queued
. 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<'a, S>(&mut self, section: S) where
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
S: Into<Cow<'a, VariedSection<'a>>>,
Queues a section/layout to be processed by the next call of
process_queued
. Can be called multiple
times to queue multiple sections for drawing.
Benefits from caching, see caching behaviour.
glyph_brush.queue(Section { text: "Hello glyph_brush", ..Section::default() });
pub fn queue_pre_positioned(
&mut self,
glyphs: Vec<(PositionedGlyph<'font>, Color, FontId)>,
bounds: Rect<f32>,
z: f32
)
[src]
&mut self,
glyphs: Vec<(PositionedGlyph<'font>, Color, FontId)>,
bounds: Rect<f32>,
z: f32
)
Queues pre-positioned glyphs to be processed by the next call of
process_queued
. Can be called multiple
times.
pub fn process_queued<F1, F2>(
&mut self,
update_texture: F1,
to_vertex: F2
) -> Result<BrushAction<V>, BrushError> where
F1: FnMut(Rect<u32>, &[u8]),
F2: Fn(GlyphVertex) -> V + Copy,
[src]
&mut self,
update_texture: F1,
to_vertex: F2
) -> Result<BrushAction<V>, BrushError> where
F1: FnMut(Rect<u32>, &[u8]),
F2: Fn(GlyphVertex) -> V + Copy,
Processes all queued sections, calling texture update logic when necessary &
returning a BrushAction
.
See queue
.
Two closures are required:
update_texture
is called when new glyph texture data has been drawn for update in the actual texture. The arguments are the rect position of the data in the texture & the byte data itself which is a singleu8
alpha value per pixel.to_vertex
maps a single glyph'sGlyphVertex
data into a generic vertex type. The mapped vertices are returned in anOk(BrushAction::Draw(vertices))
result. It's recommended to use a single vertex per glyph quad for best performance.
Trims the cache, see caching behaviour.
glyph_brush.process_queued( |rect, tex_data| update_texture(rect, tex_data), |vertex_data| into_vertex(vertex_data), )?
pub fn resize_texture(&mut self, new_width: u32, new_height: u32)
[src]
Rebuilds the logical texture cache with new dimensions. Should be avoided if possible.
Example
glyph_brush.resize_texture(512, 512);
pub fn texture_dimensions(&self) -> (u32, u32)
[src]
Returns the logical texture cache pixel dimensions (width, height)
.
pub fn add_font_bytes<'a: 'font, B: Into<SharedBytes<'a>>>(
&mut self,
font_data: B
) -> FontId
[src]
&mut self,
font_data: B
) -> FontId
Adds an additional font to the one(s) initially added on build.
Returns a new FontId
to reference this font.
Example
use glyph_brush::{GlyphBrush, GlyphBrushBuilder, Section}; // dejavu is built as default `FontId(0)` let dejavu: &[u8] = include_bytes!("../../fonts/DejaVuSans.ttf"); let mut glyph_brush: GlyphBrush<'_, Vertex> = GlyphBrushBuilder::using_font_bytes(dejavu).build(); // 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.
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]
&mut self,
section: S,
custom_layout: &G
) where
S: Into<Cow<'a, VariedSection<'a>>>,
G: GlyphPositioner,
Retains the section in the cache as if it had been used in the last draw-frame.
Should not generally be necessary, see caching behaviour.
pub fn keep_cached<'a, S>(&mut self, section: S) where
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
S: Into<Cow<'a, VariedSection<'a>>>,
Retains the section in the cache as if it had been used in the last draw-frame.
Should not generally be necessary, see caching behaviour.
impl<'font, V, H: BuildHasher + Clone> GlyphBrush<'font, V, H>
[src]
pub fn to_builder(&self) -> GlyphBrushBuilder<'font, H>
[src]
Return a GlyphBrushBuilder
prefilled with the
properties of this GlyphBrush
.
Example
let glyph_brush: GlyphBrush<'_, Vertex> = GlyphBrushBuilder::using_font(sans) .initial_cache_size((128, 128)) .build(); let new_brush: GlyphBrush<'_, Vertex> = glyph_brush.to_builder().build(); assert_eq!(new_brush.texture_dimensions(), (128, 128));
Trait Implementations
impl<'_, V, H> Debug for GlyphBrush<'_, V, H>
[src]
impl<'font, V, H> GlyphCruncher<'font> for GlyphBrush<'font, V, H> where
V: Clone + 'static,
H: BuildHasher,
[src]
V: Clone + 'static,
H: BuildHasher,
fn pixel_bounds_custom_layout<'a, S, L>(
&mut self,
section: S,
custom_layout: &L
) -> Option<Rect<i32>> where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
&mut self,
section: S,
custom_layout: &L
) -> Option<Rect<i32>> where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
fn glyphs_custom_layout<'a, 'b, S, L>(
&'b mut self,
section: S,
custom_layout: &L
) -> PositionedGlyphIter<'b, 'font> where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
&'b mut self,
section: S,
custom_layout: &L
) -> PositionedGlyphIter<'b, 'font> where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
fn fonts(&self) -> &[Font<'font>]
[src]
fn pixel_bounds<'a, S>(&mut self, section: S) -> Option<Rect<i32>> where
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
S: Into<Cow<'a, VariedSection<'a>>>,
fn glyphs<'a, 'b, S>(&'b mut self, section: S) -> PositionedGlyphIter<'b, 'font> where
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
S: Into<Cow<'a, VariedSection<'a>>>,
fn glyph_bounds_custom_layout<'a, S, L>(
&mut self,
section: S,
custom_layout: &L
) -> Option<Rect<f32>> where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
&mut self,
section: S,
custom_layout: &L
) -> Option<Rect<f32>> where
L: GlyphPositioner + Hash,
S: Into<Cow<'a, VariedSection<'a>>>,
fn glyph_bounds<'a, S>(&mut self, section: S) -> Option<Rect<f32>> where
S: Into<Cow<'a, VariedSection<'a>>>,
[src]
S: Into<Cow<'a, VariedSection<'a>>>,
Auto Trait Implementations
impl<'font, V, H> RefUnwindSafe for GlyphBrush<'font, V, H> where
H: RefUnwindSafe,
V: RefUnwindSafe,
H: RefUnwindSafe,
V: RefUnwindSafe,
impl<'font, V, H> Send for GlyphBrush<'font, V, H> where
H: Send,
V: Send,
H: Send,
V: Send,
impl<'font, V, H> Sync for GlyphBrush<'font, V, H> where
H: Sync,
V: Sync,
H: Sync,
V: Sync,
impl<'font, V, H> Unpin for GlyphBrush<'font, V, H> where
H: Unpin,
V: Unpin,
H: Unpin,
V: Unpin,
impl<'font, V, H> UnwindSafe for GlyphBrush<'font, V, H> where
H: UnwindSafe,
V: UnwindSafe,
H: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,