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
}
}
+9 -4
View File
@@ -14,21 +14,26 @@ impl Widget for ScrollText {
let title_lines = self.title.lines().count();
for (y, line) in self
let mut y = title_lines as u16;
for line in self
.text
.lines()
.skip(self.scroll)
.take(scope.rect.height as usize - title_lines)
.enumerate()
{
scope.draw_text((0, (y + title_lines) as u16), line);
y += scope.draw_text((0, y), line);
}
}
}
impl<const N: usize> ScrollState<N> {
pub fn get_selected(&self, index: usize) -> &'static str {
if index == self.0 { "\x1b[4m\x1b[1m" } else { "\x1b[1m" }
if index == self.0 {
"\x1b[4m\x1b[1m"
} else {
"\x1b[1m"
}
}
pub fn scroll(&self, index: usize, title: String, text: String) -> ScrollText {