Struct renderling_ui::GlyphCache

source ·
pub struct GlyphCache { /* private fields */ }
Expand description

A cache of glyphs.

Implementations§

source§

impl GlyphCache

source

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>>>§

source

pub fn add_font<I>(&mut self, font_data: I) -> FontId
where I: Into<F>,

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

Returns a new FontId to reference this font.

source

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>>>,

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.

source

pub fn queue<'a, S>(&mut self, section: S)
where 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")));
source

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.

source

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);
source

pub fn texture_dimensions(&self) -> (u32, u32)

Returns the logical texture cache pixel dimensions (width, height).

source

pub fn keep_cached_custom_layout<'a, S, G>( &mut self, section: S, custom_layout: &G )
where S: Into<Cow<'a, Section<'a, X>>>, G: GlyphPositioner, X: '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.

source

pub fn keep_cached<'a, S>(&mut self, section: S)
where S: Into<Cow<'a, Section<'a, X>>>, X: '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.

source

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,

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 single u8 alpha value per pixel.
  • to_vertex maps a single glyph’s GlyphVertex data into a generic vertex type. The mapped vertices are returned in an Ok(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),
)?
source

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.

source

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

§

type Target = GlyphBrush<Vec<Vertex>>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for GlyphCache

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,