pub struct TextLayoutResult {
pub width: f32,
pub height: f32,
pub line_height: f32,
pub lines: Vec<LineLayout>,
/* private fields */
}Expand description
Cached text layout result with pre-computed glyph positions.
Compute once during measure(), reuse for:
- Cursor X position rendering
- Selection highlight geometry
- Click-to-position cursor
Fields§
§width: f32Total width of laid out text
height: f32Total height of laid out text
line_height: f32Height of a single line
lines: Vec<LineLayout>Line layout information
Implementations§
Source§impl TextLayoutResult
impl TextLayoutResult
Sourcepub fn new(
width: f32,
height: f32,
line_height: f32,
glyph_x_positions: Vec<f32>,
char_to_byte: Vec<usize>,
lines: Vec<LineLayout>,
text: &str,
) -> Self
pub fn new( width: f32, height: f32, line_height: f32, glyph_x_positions: Vec<f32>, char_to_byte: Vec<usize>, lines: Vec<LineLayout>, text: &str, ) -> Self
Creates a new layout result with the given glyph positions.
Sourcepub fn get_cursor_x(&self, byte_offset: usize) -> f32
pub fn get_cursor_x(&self, byte_offset: usize) -> f32
Returns X position for cursor at given byte offset. O(1) lookup from pre-computed positions.
Sourcepub fn get_offset_for_x(&self, x: f32) -> usize
pub fn get_offset_for_x(&self, x: f32) -> usize
Returns byte offset for X position. O(log n) binary search through glyph positions.
Sourcepub fn is_valid_for(&self, text: &str) -> bool
pub fn is_valid_for(&self, text: &str) -> bool
Checks if this layout result is valid for the given text.
Sourcepub fn monospaced(text: &str, char_width: f32, line_height: f32) -> Self
pub fn monospaced(text: &str, char_width: f32, line_height: f32) -> Self
Creates a simple layout for monospaced text (for fallback).
Trait Implementations§
Source§impl Clone for TextLayoutResult
impl Clone for TextLayoutResult
Source§fn clone(&self) -> TextLayoutResult
fn clone(&self) -> TextLayoutResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TextLayoutResult
impl RefUnwindSafe for TextLayoutResult
impl Send for TextLayoutResult
impl Sync for TextLayoutResult
impl Unpin for TextLayoutResult
impl UnwindSafe for TextLayoutResult
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
Mutably borrows from an owned value. Read more