Fix scroll

This commit is contained in:
2026-07-31 15:44:22 +02:00
parent d779ac1a59
commit 4d042251b3
2 changed files with 14 additions and 7 deletions
+8
View File
@@ -42,6 +42,10 @@ impl RenderTextResult {
impl RenderScope { impl RenderScope {
pub fn draw_text<P: Into<Point>, T: Display>(&mut self, at: P, text: T) -> u16 { pub fn draw_text<P: Into<Point>, T: Display>(&mut self, at: P, text: T) -> u16 {
if self.rect.width == 0 || self.rect.height == 0 {
return 0;
}
let point: Point = at.into(); let point: Point = at.into();
let text = text.to_string(); let text = text.to_string();
@@ -140,6 +144,10 @@ impl RenderScope {
match inst { match inst {
Instr::DrawText(point, text) => { Instr::DrawText(point, text) => {
for (i, line) in text.lines().enumerate() { for (i, line) in text.lines().enumerate() {
if i as u16 + point.y >= self.rect.height {
continue;
}
print_at( print_at(
self.rect.x + point.x, self.rect.x + point.x,
self.rect.y + point.y + i as u16, self.rect.y + point.y + i as u16,
+6 -7
View File
@@ -12,16 +12,15 @@ impl Widget for ScrollText {
fn render(&self, scope: &mut crate::render::RenderScope) { fn render(&self, scope: &mut crate::render::RenderScope) {
let title_lines = scope.draw_text(0, &self.title); let title_lines = scope.draw_text(0, &self.title);
let mut y = title_lines as u16; let text = self
for line in self
.text .text
.lines() .lines()
.skip(self.scroll) .skip(self.scroll)
.take((scope.rect.height - title_lines) as usize) .map(|v| v.trim_end())
{ .collect::<Vec<_>>()
y += scope.draw_text((0, y), line); .join("\n");
}
scope.draw_text((0, title_lines), text);
} }
} }