Struct wgpu_text::TextBrush

source ·
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>
where F: Font + Sync, H: BuildHasher,

source

pub fn queue<'a, S>( &mut self, device: &Device, queue: &Queue, sections: Vec<S> ) -> Result<(), BrushError>
where S: Into<Cow<'a, Section<'a>>>,

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

source

pub fn glyph_bounds<'a, S>(&mut self, section: S) -> Option<Rect>
where S: Into<Cow<'a, Section<'a>>>,

Returns a bounding box for the section glyphs calculated using each glyph’s vertical & horizontal metrics. For more info, read about GlyphCruncher::glyph_bounds.

source

pub fn glyphs_iter<'a, 'b, S>(&'b mut self, section: S) -> SectionGlyphIter<'b>
where S: Into<Cow<'a, Section<'a>>>,

Returns an iterator over the PositionedGlyphs of the given section.

source

pub fn fonts(&self) -> &[F]

Returns the available fonts.

The FontId corresponds to the index of the font data.

source

pub fn draw<'pass>(&'pass self, rpass: &mut RenderPass<'pass>)

Draws all sections queued with queue function.

source

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]
    ]
}
source

pub fn update_matrix<M>(&self, matrix: M, queue: &Queue)
where M: Into<Matrix>,

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>
where H: Send, F: Send,

§

impl<F, H> Sync for TextBrush<F, H>
where H: Sync, F: Sync,

§

impl<F, H> Unpin for TextBrush<F, H>
where H: Unpin, F: Unpin,

§

impl<F = FontArc, H = RandomXxHashBuilder64> !UnwindSafe for TextBrush<F, H>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

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