Fix UI overflows

This commit is contained in:
2026-07-27 19:30:45 +02:00
parent 537ea52f2a
commit 7b1281aa57
2 changed files with 59 additions and 6 deletions
+50 -2
View File
@@ -16,9 +16,57 @@ pub struct RenderScope {
}
impl RenderScope {
pub fn draw_text<P: Into<Point>, T: Display>(&mut self, at: P, text: T) {
pub fn draw_text<P: Into<Point>, T: Display>(&mut self, at: P, text: T) -> u16 {
let point: Point = at.into();
let lines = text
.to_string()
.lines()
.map(|line| {
let mut chars = line.chars().peekable();
let mut new_line = String::new();
let mut len = 0;
while let Some(c) = chars.next() {
if c == '\x1b' && chars.peek() == Some(&'[') {
new_line.push(c);
while let Some(c) = chars.next() {
new_line.push(c);
if c.is_ascii_alphabetic() {
break;
}
}
continue;
}
new_line.push(c);
len += 1;
if len >= self.rect.width as usize {
new_line.push('\n');
len = 0;
}
}
new_line
})
.collect::<Vec<_>>()
.join("\n");
let lines = lines
.lines()
.take((self.rect.height - point.y) as usize)
.collect::<Vec<_>>();
let lines_len = lines.len();
self.draw_instructions
.push(Instr::DrawText(at.into(), text.to_string()));
.push(Instr::DrawText(point, lines.join("\n")));
lines_len as u16
}
}