pub fn selection_rects_for_run(
content_x: f32,
content_y: f32,
run: &EditorTextRun,
lo_local: usize,
hi_local: usize,
style: EditorStyle,
) -> Vec<Rect>Expand description
Builds viewport-space rectangles for a run-local byte selection.
lo_local..hi_local is clamped to the run layout’s UTF-8 byte length. One
rectangle is returned per intersected visual line, with rounded x/y, a
minimum width of one logical pixel, and at least px_size + 2 logical pixels
of height. Empty or reversed selections return an empty vector.
§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_editor::{input::selection::selection_rects_for_run, layout::EditorTextRun, EditorStyle};
use ailloli_ui_text::{TextLayoutParams, TextSystem};
let mut text_system = TextSystem::new();
let layout = text_system.layout_cached(TextLayoutParams::new(
"abc",
TextStyle::new(FontId::Mono, 13, Color::WHITE),
));
let run = EditorTextRun { index: 0, byte_range: 0..3, baseline_y: 10.0, layout };
let rects = selection_rects_for_run(4.0, 6.0, &run, 0, 2, EditorStyle::default());
assert_eq!(rects.len(), 1);
assert!(rects[0].x >= 4.0 && rects[0].w >= 1.0);