pub struct SdfTextRenderer { /* private fields */ }Expand description
SDF-only text renderer.
Uses only an SDF glyph atlas for rendering, with no bitmap support. This provides scalable text rendering with effects (~8 MB with default atlas).
Best for large text, titles, and text that needs effects like shadows/outlines.
Implementations§
Source§impl SdfTextRenderer
impl SdfTextRenderer
Sourcepub fn new(context: Arc<GraphicsContext>, font_system: FontSystem) -> Self
pub fn new(context: Arc<GraphicsContext>, font_system: FontSystem) -> Self
Create a new SDF text renderer with default configuration.
Sourcepub fn with_config(
context: Arc<GraphicsContext>,
font_system: FontSystem,
config: TextRendererConfig,
) -> Self
pub fn with_config( context: Arc<GraphicsContext>, font_system: FontSystem, config: TextRendererConfig, ) -> Self
Create a new SDF text renderer with custom configuration.
Sourcepub fn measure_text(&self, text: &Text) -> (f32, f32)
pub fn measure_text(&self, text: &Text) -> (f32, f32)
Measure text dimensions without rendering.
Sourcepub fn buffer_bounds(&self, buffer: &TextBuffer) -> (f32, f32)
pub fn buffer_bounds(&self, buffer: &TextBuffer) -> (f32, f32)
Get the logical (unscaled) bounds of a prepared text buffer.
Sourcepub fn get_text_metrics(&self, text: &Text) -> TextMetrics
pub fn get_text_metrics(&self, text: &Text) -> TextMetrics
Get font metrics for the given text style.
Sourcepub fn set_viewport(&mut self, viewport: Viewport)
pub fn set_viewport(&mut self, viewport: Viewport)
Set the viewport for rendering.
Note: SDF atlas doesn’t need to be cleared on scale factor change because SDF glyphs are resolution-independent.
Sourcepub fn set_sdf_config(&mut self, config: SdfConfig)
pub fn set_sdf_config(&mut self, config: SdfConfig)
Set SDF configuration.
Sourcepub fn sdf_config(&self) -> &SdfConfig
pub fn sdf_config(&self) -> &SdfConfig
Get the current SDF configuration.
Sourcepub fn prepare(&mut self, text: &Text) -> TextBuffer
pub fn prepare(&mut self, text: &Text) -> TextBuffer
Prepare text for rendering.
Sourcepub fn draw_text(&mut self, buffer: &mut TextBuffer, position: Vec2)
pub fn draw_text(&mut self, buffer: &mut TextBuffer, position: Vec2)
Draw text at a position (without effects).
Sourcepub fn draw_text_with_effects(
&mut self,
buffer: &mut TextBuffer,
position: Vec2,
effects: &TextEffects,
)
pub fn draw_text_with_effects( &mut self, buffer: &mut TextBuffer, position: Vec2, effects: &TextEffects, )
Draw text with effects at a position.
Sourcepub fn render(&mut self, render_pass: &mut RenderPass<'_>)
pub fn render(&mut self, render_pass: &mut RenderPass<'_>)
Render all queued text to the given render pass.
Sourcepub fn font_system(&self) -> Arc<RwLock<FontSystem>>
pub fn font_system(&self) -> Arc<RwLock<FontSystem>>
Get the font system.
Sourcepub fn swash_cache(&self) -> Arc<RwLock<SwashCache>>
pub fn swash_cache(&self) -> Arc<RwLock<SwashCache>>
Get the swash cache.
Sourcepub fn atlas_size(&self) -> u32
pub fn atlas_size(&self) -> u32
Get the atlas size in pixels.
Trait Implementations§
Source§impl TextRender for SdfTextRenderer
impl TextRender for SdfTextRenderer
Source§fn draw_text(&mut self, buffer: &mut TextBuffer, position: Vec2)
fn draw_text(&mut self, buffer: &mut TextBuffer, position: Vec2)
Source§fn render(&mut self, render_pass: &mut RenderPass<'_>)
fn render(&mut self, render_pass: &mut RenderPass<'_>)
Source§fn set_viewport(&mut self, viewport: Viewport)
fn set_viewport(&mut self, viewport: Viewport)
Source§fn buffer_bounds(&self, buffer: &TextBuffer) -> (f32, f32)
fn buffer_bounds(&self, buffer: &TextBuffer) -> (f32, f32)
Auto Trait Implementations§
impl Freeze for SdfTextRenderer
impl !RefUnwindSafe for SdfTextRenderer
impl Send for SdfTextRenderer
impl Sync for SdfTextRenderer
impl Unpin for SdfTextRenderer
impl UnsafeUnpin for SdfTextRenderer
impl !UnwindSafe for SdfTextRenderer
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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