ailloli_ui_editor/paint/
text_painter.rs

1//! Uniform-color text paint-item construction.
2
3use crate::layout::EditorTextRun;
4use crate::paint::EditorPaintItem;
5use crate::EditorStyle;
6
7/// Builds a uniform-color text item from an existing run layout.
8///
9/// The layout handle is reference-count cloned; no shaping or glyph copying is
10/// performed. Position is `[content_x, content_y + run.baseline_y]` in logical
11/// pixels and the color is [`EditorStyle::fg`].
12///
13/// # Examples
14///
15/// ```
16/// use ailloli_ui_core::{Color, FontId, TextStyle};
17/// use ailloli_ui_editor::{layout::EditorTextRun, paint::{text_painter::text_item, EditorPaintItem}, EditorStyle};
18/// use ailloli_ui_text::{TextLayoutParams, TextSystem};
19/// let mut system = TextSystem::new();
20/// let layout = system.layout_cached(TextLayoutParams::new("x", TextStyle::new(FontId::Mono, 13, Color::WHITE)));
21/// let run = EditorTextRun { index: 0, byte_range: 0..1, baseline_y: 12.0, layout };
22/// assert!(matches!(text_item(4.0, 5.0, &run, EditorStyle::default()), EditorPaintItem::Text { pos: [4.0, 17.0], .. }));
23/// ```
24pub fn text_item(
25    content_x: f32,
26    content_y: f32,
27    run: &EditorTextRun,
28    style: EditorStyle,
29) -> EditorPaintItem {
30    EditorPaintItem::Text {
31        pos: [content_x, content_y + run.baseline_y],
32        color: style.fg,
33        layout: run.layout.clone(),
34    }
35}