pub struct TextRenderer { /* private fields */ }Expand description
A managed renderer for Zentype that handles atlas management, pipeline state, and efficient batching.
Implementations§
Source§impl TextRenderer
impl TextRenderer
Sourcepub fn new(
device: Arc<Device>,
queue: &Queue,
config: &SurfaceConfiguration,
font_provider: Box<dyn FontProvider>,
rasterizer: Box<dyn Rasterizer>,
atlas: GlyphAtlas,
) -> Self
pub fn new( device: Arc<Device>, queue: &Queue, config: &SurfaceConfiguration, font_provider: Box<dyn FontProvider>, rasterizer: Box<dyn Rasterizer>, atlas: GlyphAtlas, ) -> Self
Creates a new TextRenderer with the provided engine implementations.
Sourcepub fn set_font_provider(&mut self, provider: Box<dyn FontProvider>)
pub fn set_font_provider(&mut self, provider: Box<dyn FontProvider>)
Sets a custom font provider.
Sourcepub fn set_rasterizer(&mut self, rasterizer: Box<dyn Rasterizer>)
pub fn set_rasterizer(&mut self, rasterizer: Box<dyn Rasterizer>)
Sets a custom rasterizer.
Sourcepub fn draw(
&mut self,
queue: &Queue,
text: &str,
pos: [f32; 2],
options: &TextOptions,
) -> ShapedBuffer
pub fn draw( &mut self, queue: &Queue, text: &str, pos: [f32; 2], options: &TextOptions, ) -> ShapedBuffer
Prepares a string for rendering in the current frame at the specified position. This will shape the text and ensure all required glyphs are in the atlas. Returns the ShapedBuffer which can be used for hit-testing and interactivity.
Sourcepub fn draw_rect(
&mut self,
pos: [f32; 2],
size: [f32; 2],
color: Color,
clip_rect: [f32; 4],
)
pub fn draw_rect( &mut self, pos: [f32; 2], size: [f32; 2], color: Color, clip_rect: [f32; 4], )
Queues a single colored rectangle for rendering with optional clipping. Useful for cursors, selections, and custom UI elements.
Sourcepub fn hit_test(
&self,
buffer: &ShapedBuffer,
pos: [f32; 2],
options: &TextOptions,
mouse_pos: [f32; 2],
) -> usize
pub fn hit_test( &self, buffer: &ShapedBuffer, pos: [f32; 2], options: &TextOptions, mouse_pos: [f32; 2], ) -> usize
Finds the character index at the given screen-space coordinates. This handles the translation from screen space to text-local space, accounting for position and padding.
Sourcepub fn position_at(
&self,
buffer: &ShapedBuffer,
pos: [f32; 2],
options: &TextOptions,
index: usize,
) -> Option<[f32; 2]>
pub fn position_at( &self, buffer: &ShapedBuffer, pos: [f32; 2], options: &TextOptions, index: usize, ) -> Option<[f32; 2]>
Returns the screen-space position for a given character index.
Sourcepub fn render<'a>(&'a mut self, rpass: &mut RenderPass<'a>)
pub fn render<'a>(&'a mut self, rpass: &mut RenderPass<'a>)
Submits the accumulated text instances to the provided RenderPass.
Sourcepub fn resize(&mut self, queue: &Queue, width: u32, height: u32)
pub fn resize(&mut self, queue: &Queue, width: u32, height: u32)
Updates the projection matrix to match the new surface size.
Sourcepub fn font_system(&self) -> Arc<Mutex<FontSystem>>
pub fn font_system(&self) -> Arc<Mutex<FontSystem>>
Access the underlying font system.