[−][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::glyph_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::draw_cache_position_tolerance
(struct.GlyphBrushBuilder.html#method.draw_cache_position_tolerance).
Implementations
impl<F, V, X, H: BuildHasher> GlyphBrush<V, X, F, H>
[src]
pub fn add_font<I: Into<F>>(&mut self, font_data: I) -> FontId
[src]
Adds an additional font to the one(s) initially added on build.
Returns a new FontId
to reference this font.
impl<F, V, X, H> GlyphBrush<V, X, F, H> where
F: Font,
X: Clone + Hash,
V: Clone + 'static,
H: BuildHasher,
[src]
F: Font,
X: Clone + Hash,
V: Clone + 'static,
H: BuildHasher,
pub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G) where
G: GlyphPositioner,
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
[src]
G: GlyphPositioner,
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
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
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
[src]
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
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::default().add_text(Text::new("Hello glyph_brush")));
pub fn queue_pre_positioned(
&mut self,
glyphs: Vec<SectionGlyph>,
extra: Vec<X>,
bounds: Rect
)
[src]
&mut self,
glyphs: Vec<SectionGlyph>,
extra: Vec<X>,
bounds: Rect
)
Queues pre-positioned glyphs to be processed by the next call of
process_queued
. Can be called multiple
times.
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 keep_cached_custom_layout<'a, S, G>(
&mut self,
section: S,
custom_layout: &G
) where
S: Into<Cow<'a, Section<'a>>>,
G: GlyphPositioner,
[src]
&mut self,
section: S,
custom_layout: &G
) where
S: Into<Cow<'a, Section<'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, Section<'a>>>,
[src]
S: Into<Cow<'a, Section<'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<F, V, X, H> GlyphBrush<V, X, F, H> where
F: Font + Sync,
X: Clone + Hash + PartialEq,
V: Clone + 'static,
H: BuildHasher,
[src]
F: Font + Sync,
X: Clone + Hash + PartialEq,
V: Clone + 'static,
H: BuildHasher,
pub fn process_queued<Up, VF>(
&mut self,
update_texture: Up,
to_vertex: VF
) -> Result<BrushAction<V>, BrushError> where
Up: FnMut(Rectangle<u32>, &[u8]),
VF: Fn(GlyphVertex<'_, X>) -> V + Copy,
[src]
&mut self,
update_texture: Up,
to_vertex: VF
) -> Result<BrushAction<V>, BrushError> where
Up: FnMut(Rectangle<u32>, &[u8]),
VF: Fn(GlyphVertex<'_, X>) -> 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 is_draw_cached(&self, font_id: FontId, glyph: &Glyph) -> bool
[src]
Returns true
if this glyph is currently present in the draw cache texture.
So false
means either this glyph is invisible, like ' '
, or hasn't been queued &
processed yet.
impl<F: Font + Clone, V, X, H: BuildHasher + Clone> GlyphBrush<V, X, F, H>
[src]
pub fn to_builder(&self) -> GlyphBrushBuilder<F, 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<F, V, X, H> Debug for GlyphBrush<V, X, F, H>
[src]
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,
[src]
X: Clone + Hash,
F: Font,
V: Clone + 'static,
H: BuildHasher,
pub 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>>>,
[src]
&'b mut self,
section: S,
custom_layout: &L
) -> SectionGlyphIter<'b> where
X: 'a,
L: GlyphPositioner + Hash,
S: Into<Cow<'a, Section<'a, X>>>,
pub 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>>>,
[src]
&mut self,
section: S,
custom_layout: &L
) -> Option<Rect> where
X: 'a,
L: GlyphPositioner + Hash,
S: Into<Cow<'a, Section<'a, X>>>,
pub fn fonts(&self) -> &[F]
[src]
pub fn glyphs<'a, 'b, S>(&'b mut self, section: S) -> SectionGlyphIter<'b> where
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
[src]
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
pub fn glyph_bounds<'a, S>(&mut self, section: S) -> Option<Rect> where
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
[src]
X: 'a,
S: Into<Cow<'a, Section<'a, X>>>,
Auto Trait Implementations
impl<V, X, F, H> RefUnwindSafe for GlyphBrush<V, X, F, H> where
F: RefUnwindSafe,
H: RefUnwindSafe,
V: RefUnwindSafe,
X: RefUnwindSafe,
F: RefUnwindSafe,
H: RefUnwindSafe,
V: RefUnwindSafe,
X: RefUnwindSafe,
impl<V, X, F, H> Send for GlyphBrush<V, X, F, H> where
F: Send,
H: Send,
V: Send,
X: Send,
F: Send,
H: Send,
V: Send,
X: Send,
impl<V, X, F, H> Sync for GlyphBrush<V, X, F, H> where
F: Sync,
H: Sync,
V: Sync,
X: Sync,
F: Sync,
H: Sync,
V: Sync,
X: Sync,
impl<V, X, F, H> Unpin for GlyphBrush<V, X, F, H> where
F: Unpin,
H: Unpin,
V: Unpin,
X: Unpin,
F: Unpin,
H: Unpin,
V: Unpin,
X: Unpin,
impl<V, X, F, H> UnwindSafe for GlyphBrush<V, X, F, H> where
F: UnwindSafe,
H: UnwindSafe,
V: UnwindSafe,
X: UnwindSafe,
F: UnwindSafe,
H: UnwindSafe,
V: UnwindSafe,
X: 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,
pub 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> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
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.
pub 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.
pub 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>,