Struct renderling_ui::GlyphCache
source · pub struct GlyphCache { /* private fields */ }Expand description
A cache of glyphs.
Implementations§
source§impl GlyphCache
impl GlyphCache
sourcepub fn get_updated(
&mut self
) -> (Option<Vec<Vertex>>, Option<ImageBuffer<Luma<u8>, Vec<u8>>>)
pub fn get_updated( &mut self ) -> (Option<Vec<Vertex>>, Option<ImageBuffer<Luma<u8>, Vec<u8>>>)
Process any brushes, updating textures, etc.
Returns a new mesh if the mesh needs to be updated. Returns a new texture if the texture needs to be updated.
The texture and mesh are meant to be used to build or update a
Renderlet to display.
Methods from Deref<Target = GlyphBrush<Vec<Vertex>>>§
sourcepub fn add_font<I>(&mut self, font_data: I) -> FontIdwhere
I: Into<F>,
pub fn add_font<I>(&mut self, font_data: I) -> FontIdwhere
I: Into<F>,
Adds an additional font to the one(s) initially added on build.
Returns a new FontId to reference this font.
sourcepub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G)
pub fn queue_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G)
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.
sourcepub fn queue<'a, S>(&mut self, section: S)
pub fn queue<'a, S>(&mut self, section: S)
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")));sourcepub fn queue_pre_positioned(
&mut self,
glyphs: Vec<SectionGlyph>,
extra: Vec<X>,
bounds: Rect
)
pub fn queue_pre_positioned( &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.
sourcepub fn resize_texture(&mut self, new_width: u32, new_height: u32)
pub fn resize_texture(&mut self, new_width: u32, new_height: u32)
Rebuilds the logical texture cache with new dimensions. Should be avoided if possible.
§Example
glyph_brush.resize_texture(512, 512);sourcepub fn texture_dimensions(&self) -> (u32, u32)
pub fn texture_dimensions(&self) -> (u32, u32)
Returns the logical texture cache pixel dimensions (width, height).
sourcepub fn keep_cached_custom_layout<'a, S, G>(
&mut self,
section: S,
custom_layout: &G
)
pub fn keep_cached_custom_layout<'a, S, G>( &mut self, section: S, custom_layout: &G )
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.
sourcepub fn keep_cached<'a, S>(&mut self, section: S)
pub fn keep_cached<'a, S>(&mut self, section: S)
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.
sourcepub fn process_queued<Up, VF>(
&mut self,
update_texture: Up,
to_vertex: VF
) -> Result<BrushAction<V>, BrushError>
pub fn process_queued<Up, VF>( &mut self, update_texture: Up, to_vertex: VF ) -> Result<BrushAction<V>, BrushError>
Processes all queued sections, calling texture update logic when necessary &
returning a BrushAction.
See queue.
Two closures are required:
update_textureis 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 singleu8alpha value per pixel.to_vertexmaps a single glyph’sGlyphVertexdata 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),
)?sourcepub fn is_draw_cached(&self, font_id: FontId, glyph: &Glyph) -> bool
pub fn is_draw_cached(&self, font_id: FontId, glyph: &Glyph) -> bool
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.
sourcepub fn to_builder(&self) -> GlyphBrushBuilder<F, H>
pub fn to_builder(&self) -> GlyphBrushBuilder<F, H>
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§
source§impl Deref for GlyphCache
impl Deref for GlyphCache
Auto Trait Implementations§
impl Freeze for GlyphCache
impl !RefUnwindSafe for GlyphCache
impl Send for GlyphCache
impl Sync for GlyphCache
impl Unpin for GlyphCache
impl !UnwindSafe for GlyphCache
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more