Skip to main content

TextRenderer

Struct TextRenderer 

Source
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

Source

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.

Source

pub fn set_font_provider(&mut self, provider: Box<dyn FontProvider>)

Sets a custom font provider.

Source

pub fn set_rasterizer(&mut self, rasterizer: Box<dyn Rasterizer>)

Sets a custom rasterizer.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn render<'a>(&'a mut self, rpass: &mut RenderPass<'a>)

Submits the accumulated text instances to the provided RenderPass.

Source

pub fn resize(&mut self, queue: &Queue, width: u32, height: u32)

Updates the projection matrix to match the new surface size.

Source

pub fn font_system(&self) -> Arc<Mutex<FontSystem>>

Access the underlying font system.

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