From 743b22b3c471e864947681e25d46e29dff9b91af Mon Sep 17 00:00:00 2001 From: nyx Date: Wed, 2 Oct 2024 03:52:55 -0400 Subject: [PATCH 1/2] dont allow scrolling when last line is visible --- tui/src/floating_text.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tui/src/floating_text.rs b/tui/src/floating_text.rs index 52e0c50c..f6aba95a 100644 --- a/tui/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -36,6 +36,7 @@ pub struct FloatingText { v_scroll: usize, h_scroll: usize, mode_title: &'static str, + frame_height: usize, } macro_rules! style { @@ -143,6 +144,7 @@ impl FloatingText { max_line_width, v_scroll: 0, h_scroll: 0, + frame_height: 0, } } @@ -173,6 +175,7 @@ impl FloatingText { max_line_width, h_scroll: 0, v_scroll: 0, + frame_height: 0, }) } @@ -185,7 +188,8 @@ impl FloatingText { } fn scroll_down(&mut self) { - if self.v_scroll + 1 < self.src.len() { + let visible_lines = self.get_visible_lines(); + if self.v_scroll + visible_lines < self.src.len() { self.v_scroll += 1; } } @@ -207,10 +211,16 @@ impl FloatingText { self.h_scroll += 1; } } + + fn get_visible_lines(&self) -> usize { + self.frame_height.saturating_sub(2) + } } 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) From 5cac3086fc0c27f28dc64519f7816488915c9e5e Mon Sep 17 00:00:00 2001 From: Nyx <144965845+nnyyxxxx@users.noreply.github.com> Date: Wed, 2 Oct 2024 03:59:43 -0400 Subject: [PATCH 2/2] apply changes proposed by adam Co-authored-by: Adam Perkowski --- tui/src/floating_text.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tui/src/floating_text.rs b/tui/src/floating_text.rs index f6aba95a..89d42bb3 100644 --- a/tui/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -188,7 +188,7 @@ impl FloatingText { } fn scroll_down(&mut self) { - let visible_lines = self.get_visible_lines(); + let visible_lines = self.frame_height.saturating_sub(2); if self.v_scroll + visible_lines < self.src.len() { self.v_scroll += 1; } @@ -211,10 +211,6 @@ impl FloatingText { self.h_scroll += 1; } } - - fn get_visible_lines(&self) -> usize { - self.frame_height.saturating_sub(2) - } } impl FloatContent for FloatingText {