Skip to main content

TextRenderer

Trait TextRenderer 

pub trait TextRenderer: Send + Sync {
    // Required methods
    fn layout_text(
        &self,
        text: &str,
        font: &AssetHandle<Font>,
        font_id: AssetUUID,
        font_size: f32,
        max_width: Option<f32>,
    ) -> Box<dyn TextLayout>;
    fn queue_text(
        &self,
        layout: &dyn TextLayout,
        pos: Vec2,
        color: Vec4,
        z_index: i32,
    );
    fn flush(
        &self,
        device: &(dyn GraphicsDevice + 'static),
        encoder: &mut dyn CommandEncoder,
        color_target: &TextureViewId,
    ) -> Result<(), Box<dyn Error + Send + Sync>>;
}
Expand description

A service responsible for laying out and rendering text.

This trait decouples the high-level UI rendering from specific text layout and rasterization engines. Concrete implementations in khora-infra may use libraries like glyphon, glyph_brush, or custom “maison” solutions.

Required Methods§

fn layout_text( &self, text: &str, font: &AssetHandle<Font>, font_id: AssetUUID, font_size: f32, max_width: Option<f32>, ) -> Box<dyn TextLayout>

Computes the layout for a string with the specified font and size.

The returned [TextLayout] can then be queued for rendering.

fn queue_text( &self, layout: &dyn TextLayout, pos: Vec2, color: Vec4, z_index: i32, )

Queues a previously computed layout for rendering at a specific position.

The text is not rendered immediately but batch-processed during [flush].

fn flush( &self, device: &(dyn GraphicsDevice + 'static), encoder: &mut dyn CommandEncoder, color_target: &TextureViewId, ) -> Result<(), Box<dyn Error + Send + Sync>>

Renders all queued text and updates the glyph cache.

This should be called once per frame, usually within a specialized render pass.

Implementors§