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>>>§
pub 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.
pub 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.
pub 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")));
pub 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.
pub 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);
pub fn texture_dimensions(&self) -> (u32, u32)
pub fn texture_dimensions(&self) -> (u32, u32)
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,
)
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.
pub 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.
pub 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_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
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.
pub 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 Debug for GlyphCache
impl Debug for GlyphCache
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);