From 38138334b712d1cff80be05f58a8c9469cbd795a Mon Sep 17 00:00:00 2001 From: nyx Date: Thu, 31 Oct 2024 14:37:01 -0400 Subject: [PATCH] dont allow scrolling when last line is visible (#729) * dont allow scrolling when last line is visible * apply changes proposed by adam Co-authored-by: Adam Perkowski --------- Co-authored-by: nyx Co-authored-by: Adam Perkowski --- tui/src/floating_text.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tui/src/floating_text.rs b/tui/src/floating_text.rs index da988afd..be22958c 100644 --- a/tui/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -30,6 +30,7 @@ pub struct FloatingText { v_scroll: usize, h_scroll: usize, mode_title: String, + frame_height: usize, } macro_rules! style { @@ -137,6 +138,7 @@ impl FloatingText { max_line_width, v_scroll: 0, h_scroll: 0, + frame_height: 0, } } @@ -167,11 +169,13 @@ impl FloatingText { max_line_width, h_scroll: 0, v_scroll: 0, + frame_height: 0, }) } fn scroll_down(&mut self) { - if self.v_scroll + 1 < self.src.len() { + let visible_lines = self.frame_height.saturating_sub(2); + if self.v_scroll + visible_lines < self.src.len() { self.v_scroll += 1; } } @@ -197,6 +201,8 @@ impl FloatingText { impl FloatContent for FloatingText { fn draw(&mut self, frame: &mut Frame, area: Rect) { + self.frame_height = area.height as usize; + // Define the Block with a border and background color let block = Block::default() .borders(Borders::ALL)