Function byte_at_point

Source
pub fn byte_at_point(
    viewport: EditorViewport,
    runs: &[EditorTextRun],
    style: EditorStyle,
    buffer_len_bytes: usize,
    pos: Point,
) -> EditorHitTest
Expand description

Maps a screen point to the closest visible run’s UTF-8 source byte.

Above/below points select the first/last run. With no runs the result is buffer_len_bytes. Local run results are clamped to shaped text length.

§Examples

use ailloli_ui_core::{Point, Rect};
use ailloli_ui_editor::{input::hit_test::byte_at_point, EditorConfig, EditorStyle, EditorViewport};
use ailloli_ui_text::TextEditState;
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 80.0, 40.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(byte_at_point(viewport, &[], EditorStyle::default(), 12, Point::new(1.0, 1.0)).byte, 12);