Function caret_x_at

Source
pub fn caret_x_at(laid: &LaidOutText, byte_idx: usize) -> f32
Expand description

Maps a UTF-8 byte index to X in layout space (cluster-aware).

The returned logical-pixel X is the left edge of a zero-width downstream caret. Byte positions inside one shaped cluster map to that cluster’s caret geometry.

§Examples

use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{caret_x_at, layout_text, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let laid = layout_text(&mut engine, TextLayoutParams::new("abc", TextStyle::new(FontId::Ui, 16, Color::WHITE)));
assert!(caret_x_at(&laid, laid.text().len()) >= caret_x_at(&laid, 0));