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,26 +137,32 @@ 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(' ') {
if c == '\n' { let word_length = word.len() as u16 * kerning;
curr_pos.y += kerning; if curr_pos.x + word_length > 240 {
continue;
}
if c == ' ' {
curr_pos.x += kerning;
continue;
}
if curr_pos.x + kerning > 240 {
curr_pos.x = original_x; curr_pos.x = original_x;
curr_pos.y += kerning; curr_pos.y += kerning;
} }
if curr_pos.y + kerning > 240 {
curr_pos.y = 0; for c in word.chars() {
if c == '\n' {
curr_pos.y += kerning;
continue;
}
if curr_pos.x + kerning > 240 {
curr_pos.x = original_x;
curr_pos.y += kerning;
}
if curr_pos.y + kerning > 240 {
curr_pos.y = 0;
}
Letter::from(c, fg, bg)
.iter()
.draw(display, curr_pos, scale);
curr_pos.x += kerning;
} }
Letter::from(c, fg, bg)
.iter()
.draw(display, curr_pos, scale);
curr_pos.x += kerning; curr_pos.x += kerning;
} }
} }