Struct TextRenderer

Source
pub struct TextRenderer { /* private fields */ }
Expand description

The main struct that handles text rendering to the screen. Use this struct to load fonts and draw text during a render pass.

Create one with a TextRendererBuilder.

Implementations§

Source§

impl TextRenderer

Source

pub fn resize(&self, new_size: (u32, u32), queue: &Queue)

Configure the text renderer to draw to a surface with the given dimensions.

You want to use this when the window resizes. You might also want to use it before drawing to a texture which is smaller than the screen, if you so choose.

Source

pub fn load_font<F>(&mut self, font: F, size: FontSize) -> FontId
where F: Font + Send + Sync + 'static,

Loads a font for use in the text renderer.

Source

pub fn load_font_with_sdf<F>( &mut self, font: F, size: FontSize, sdf_settings: SdfSettings, ) -> FontId
where F: Font + Send + Sync + 'static,

Loads a font for use in the text renderer with sdf rendering.

Any font can be used for sdf rendering. A font with SDF enabled can be scaled up without pixellation, and can have effects applied to it. However, creating the textures for each character will take longer and the textures will take up more space on the GPU. So if you don’t need any of these effects, use TextRenderer::load_font instead.

Source

pub fn draw_text<'pass>( &'pass self, render_pass: &mut RenderPass<'pass>, text: &'pass Text, )

Draws a Text object to the given render pass.

Source

pub fn font_uses_sdf(&self, font: FontId) -> bool

Returns whether a given font was loaded with sdf enabled.

Source

pub fn generate_char_textures( &mut self, chars: impl Iterator<Item = char>, font: FontId, device: &Device, queue: &Queue, )

Creates and caches the character textures necessary to draw a certain string with a given font.

This is called every time a new Text is created, but you might also want to call it yourself if you know you’re going to be displaying some text in the future and want to generate the character textures in advance.

For example, if you are making a game with a score display that might change every frame, you might want to cache all the characters from ‘0’ to ‘9’ beforehand to save this from happening between frames.

Trait Implementations§

Source§

impl Debug for TextRenderer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

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

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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