Format overflowing words to go to next line

This commit is contained in:
Sofia 2025-09-13 15:06:02 +03:00
parent 3a827cfde7
commit 0806f9803e

View File

@ -137,15 +137,18 @@ pub fn draw_text<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
let kerning = 9 * scale; let kerning = 9 * scale;
let original_x = position.x; let original_x = position.x;
for c in text.chars() { for word in text.split(' ') {
let word_length = word.len() as u16 * kerning;
if curr_pos.x + word_length > 240 {
curr_pos.x = original_x;
curr_pos.y += kerning;
}
for c in word.chars() {
if c == '\n' { if c == '\n' {
curr_pos.y += kerning; curr_pos.y += kerning;
continue; continue;
} }
if c == ' ' {
curr_pos.x += kerning;
continue;
}
if curr_pos.x + kerning > 240 { if curr_pos.x + kerning > 240 {
curr_pos.x = original_x; curr_pos.x = original_x;
curr_pos.y += kerning; curr_pos.y += kerning;
@ -159,6 +162,9 @@ pub fn draw_text<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
.draw(display, curr_pos, scale); .draw(display, curr_pos, scale);
curr_pos.x += kerning; curr_pos.x += kerning;
} }
curr_pos.x += kerning;
}
} }
pub struct Letter { pub struct Letter {