Function caret_rect_at

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

Maps a UTF-8 byte index to a caret rectangle in layout space.

width is the requested logical-pixel caret thickness. Negative and NaN values behave as zero. The rectangle height follows the shaped line; its width is at least the normalized requested width. A downstream affinity is used at ambiguous boundaries.

ยงExamples

use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{caret_rect_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)));
let caret = caret_rect_at(&laid, 0, 2.0);
assert!(caret.w >= 2.0);
assert!(caret.h >= 0.0);