Skip to main content

hit_test_text

Function hit_test_text 

Source
pub fn hit_test_text(
    text: &str,
    origin_x: f32,
    pointer_x: f32,
    avg_advance: f32,
) -> usize
Expand description

Hit-test against a single-line run with a uniform per-char advance. Returns the byte offset whose glyph the pointer landed nearest.

pointer_x is in the same coordinate space as origin_x (typically the text run’s leading edge, in logical pixels). avg_advance is the average glyph advance for the run; callers without a real shaper can pass size_px * 0.55 as a rough fallback.

This is a tide-over implementation for tests and for input.rs while the full ShapedRunIndex path is being wired; the renderer-side cosmic-text Buffer::hit is the canonical path once the cache lands.