pub struct TextBrush<F = FontArc, H = DefaultSectionHasher> { /* private fields */ }
Expand description
Wrapper over glyph_brush::GlyphBrush
. In charge of drawing text.
Used for queuing and rendering text with TextBrush::draw
.
Implementations§
source§impl<F, H> TextBrush<F, H>
impl<F, H> TextBrush<F, H>
sourcepub fn queue<'a, S>(
&mut self,
device: &Device,
queue: &Queue,
sections: Vec<S>
) -> Result<(), BrushError>
pub fn queue<'a, S>( &mut self, device: &Device, queue: &Queue, sections: Vec<S> ) -> Result<(), BrushError>
Queues section for drawing, processes all queued text and updates the inner vertex buffer, unless the text vertices remain unmodified when compared to the last frame.
If utilizing depth, the sections
list should have Section
s ordered from
furthest to closest. They will be drawn in the order they are given.
- This method should be called every frame.
If not called when required, the draw functions will continue drawing data from the inner vertex buffer meaning they will redraw old vertices.
To learn about GPU texture caching, see
caching behaviour
sourcepub fn glyph_bounds<'a, S>(&mut self, section: S) -> Option<Rect>
pub fn glyph_bounds<'a, S>(&mut self, section: S) -> Option<Rect>
Returns a bounding box for the section glyphs calculated using each
glyph’s vertical & horizontal metrics. For more info, read about
GlyphCruncher::glyph_bounds
.
sourcepub fn glyphs_iter<'a, 'b, S>(&'b mut self, section: S) -> SectionGlyphIter<'b>
pub fn glyphs_iter<'a, 'b, S>(&'b mut self, section: S) -> SectionGlyphIter<'b>
Returns an iterator over the PositionedGlyph
s of the given section.
sourcepub fn fonts(&self) -> &[F]
pub fn fonts(&self) -> &[F]
Returns the available fonts.
The FontId
corresponds to the index of the font data.
sourcepub fn draw<'pass>(&'pass self, rpass: &mut RenderPass<'pass>)
pub fn draw<'pass>(&'pass self, rpass: &mut RenderPass<'pass>)
Draws all sections queued with queue
function.
sourcepub fn resize_view(&self, width: f32, height: f32, queue: &Queue)
pub fn resize_view(&self, width: f32, height: f32, queue: &Queue)
Resizes the view matrix. Updates the default orthographic view matrix with provided dimensions and uses it for rendering.
Run this function whenever the surface config is resized. Surface dimensions are most commonly width and height.
Matrix:
pub fn ortho(width: f32, height: f32) -> [[f32; 4]; 4] {
[
[2.0 / width, 0.0, 0.0, 0.0],
[0.0, -2.0 / height, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[-1.0, 1.0, 0.0, 1.0]
]
}
sourcepub fn update_matrix<M>(&self, matrix: M, queue: &Queue)
pub fn update_matrix<M>(&self, matrix: M, queue: &Queue)
Resizes the view. Updates text rendering matrix with the provided one.
Use Self::resize_view()
to update and replace the current render matrix
with a default orthographic matrix.
Feel free to use [ortho()
] to create more complex matrices by yourself.
Auto Trait Implementations§
impl<F = FontArc, H = RandomXxHashBuilder64> !Freeze for TextBrush<F, H>
impl<F = FontArc, H = RandomXxHashBuilder64> !RefUnwindSafe for TextBrush<F, H>
impl<F, H> Send for TextBrush<F, H>
impl<F, H> Sync for TextBrush<F, H>
impl<F, H> Unpin for TextBrush<F, H>
impl<F = FontArc, H = RandomXxHashBuilder64> !UnwindSafe for TextBrush<F, H>
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> 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