Function line_number_items

Source
pub fn line_number_items(
    viewport: EditorViewport,
    runs: &[EditorTextRun],
    style: EditorStyle,
    theme: CodeTheme,
    active_line_index: Option<usize>,
    text_system: &mut TextSystem,
) -> Vec<EditorPaintItem>
Expand description

Builds shaped, one-based line numbers for visible runs.

Numbers are right-aligned before a fold-marker reserve and clamped to the gutter’s left edge. The active logical index uses the active theme color. Without a gutter, the result is empty.

§Panics

Panics in overflow-checking builds if a run index is usize::MAX.

§Examples

use ailloli_ui_core::{Color, FontId, Rect, TextStyle};
use ailloli_ui_editor::{layout::EditorTextRun, paint::gutter_painter::line_number_items, CodeEditorConfig, CodeTheme, EditorConfig, EditorStyle, EditorViewport};
use ailloli_ui_text::{TextEditState, TextLayoutParams, TextSystem};
let mut system = TextSystem::new();
let layout = system.layout_cached(TextLayoutParams::new("x", TextStyle::new(FontId::Mono, 13, Color::WHITE)));
let run = EditorTextRun { index: 0, byte_range: 0..1, baseline_y: 12.0, layout };
let viewport = EditorViewport::with_gutter(Rect::new(0.0, 0.0, 120.0, 60.0), EditorConfig::default(), &TextEditState::new(), Some(CodeEditorConfig::default().gutter));
assert_eq!(line_number_items(viewport, &[run], EditorStyle::default(), CodeTheme::default(), Some(0), &mut system).len(), 1);