ltk/widget/text_edit/
tabs.rsuse crate::render::Canvas;
use super::theme;
use super::TextFont;
pub( crate ) fn tab_width( canvas: &Canvas, font: &TextFont, px: f32 ) -> f32
{
font.measure_char( canvas, '0', px ) * theme::TAB_COLUMNS
}
pub( crate ) fn next_stop( x: f32, tab_w: f32 ) -> f32
{
if tab_w <= 0.0 { return x; }
( ( x / tab_w ).floor() + 1.0 ) * tab_w
}
pub( crate ) fn line_x( canvas: &Canvas, font: &TextFont, value: &str, start: usize, at: usize, px: f32 ) -> f32
{
let text = &value[ start..at ];
if !text.contains( '\t' ) { return font.measure( canvas, text, px ); }
let tab_w = tab_width( canvas, font, px );
let mut x = 0.0;
for ( i, piece ) in text.split( '\t' ).enumerate()
{
if i > 0 { x = next_stop( x, tab_w ); }
if !piece.is_empty() { x += font.measure( canvas, piece, px ); }
}
x
}