Fix UI overflows
This commit is contained in:
+50
-2
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user