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
impl TextRenderer
Sourcepub fn resize(&self, new_size: (u32, u32), queue: &Queue)
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.
Sourcepub fn load_font<F>(&mut self, font: F, size: FontSize) -> FontId
pub fn load_font<F>(&mut self, font: F, size: FontSize) -> FontId
Loads a font for use in the text renderer.
Sourcepub fn load_font_with_sdf<F>(
&mut self,
font: F,
size: FontSize,
sdf_settings: SdfSettings,
) -> FontId
pub fn load_font_with_sdf<F>( &mut self, font: F, size: FontSize, sdf_settings: SdfSettings, ) -> FontId
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.
Sourcepub fn draw_text<'pass>(
&'pass self,
render_pass: &mut RenderPass<'pass>,
text: &'pass Text,
)
pub fn draw_text<'pass>( &'pass self, render_pass: &mut RenderPass<'pass>, text: &'pass Text, )
Draws a Text object to the given render pass.
Sourcepub fn font_uses_sdf(&self, font: FontId) -> bool
pub fn font_uses_sdf(&self, font: FontId) -> bool
Returns whether a given font was loaded with sdf enabled.
Sourcepub fn generate_char_textures(
&mut self,
chars: impl Iterator<Item = char>,
font: FontId,
device: &Device,
queue: &Queue,
)
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§
Auto Trait Implementations§
impl !Freeze for TextRenderer
impl !RefUnwindSafe for TextRenderer
impl Send for TextRenderer
impl Sync for TextRenderer
impl Unpin for TextRenderer
impl !UnwindSafe for TextRenderer
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