Fixing scrollbar view content

This commit is contained in:
Marco De Araujo 2026-01-11 14:06:12 -04:00
parent 000e31a14f
commit 60e4fa3b9d
2 changed files with 14 additions and 10 deletions

View file

@ -178,17 +178,21 @@ impl App {
return; return;
} }
let max_scroll = state
.get_total_lenght()
.saturating_sub(area[0].height as usize)
.saturating_add(1);
state.scroll_state = state
.scroll_state
.content_length(max_scroll.max(1))
.viewport_content_length(area[0].height as usize);
let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight) let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(Some("")) .begin_symbol(Some(""))
.end_symbol(Some("")); .end_symbol(Some(""));
frame.render_stateful_widget( frame.render_stateful_widget(scrollbar, area[1], &mut state.scroll_state);
scrollbar,
area[1],
&mut state
.scroll_state
.viewport_content_length(area[0].height as usize),
);
} }
fn handle_events(&mut self) -> io::Result<()> { fn handle_events(&mut self) -> io::Result<()> {

View file

@ -18,10 +18,10 @@ const MAX_NAME_LENGTH: usize = 30;
pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut DashboardViewState) { pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut DashboardViewState) {
let available_height = area.height as usize; let available_height = area.height as usize;
let total_lenght = state.get_total_lenght(); let max_scroll = state.get_total_lenght().saturating_sub(available_height);
if (state.scroll_state.get_position() + available_height) > total_lenght { if state.scroll_state.get_position() > max_scroll {
state.scroll_state = state.scroll_state.position(total_lenght - available_height); state.scroll_state = state.scroll_state.position(max_scroll);
} }
let scroll_pos = state.scroll_state.get_position(); let scroll_pos = state.scroll_state.get_position();