diff --git a/pulse-ui/src/render.rs b/pulse-ui/src/render.rs index 019abc9..cb58646 100644 --- a/pulse-ui/src/render.rs +++ b/pulse-ui/src/render.rs @@ -42,6 +42,10 @@ impl RenderTextResult { impl RenderScope { pub fn draw_text, 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 text = text.to_string(); @@ -140,6 +144,10 @@ impl RenderScope { match inst { Instr::DrawText(point, text) => { for (i, line) in text.lines().enumerate() { + if i as u16 + point.y >= self.rect.height { + continue; + } + print_at( self.rect.x + point.x, self.rect.y + point.y + i as u16, diff --git a/pulse-ui/src/widget/scroll.rs b/pulse-ui/src/widget/scroll.rs index 9f80ac7..62b134f 100644 --- a/pulse-ui/src/widget/scroll.rs +++ b/pulse-ui/src/widget/scroll.rs @@ -12,16 +12,15 @@ impl Widget for ScrollText { fn render(&self, scope: &mut crate::render::RenderScope) { let title_lines = scope.draw_text(0, &self.title); - let mut y = title_lines as u16; - - for line in self + let text = self .text .lines() .skip(self.scroll) - .take((scope.rect.height - title_lines) as usize) - { - y += scope.draw_text((0, y), line); - } + .map(|v| v.trim_end()) + .collect::>() + .join("\n"); + + scope.draw_text((0, title_lines), text); } }