diff --git a/src/ui/app.rs b/src/ui/app.rs index 96e2e2d..9791d8b 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -178,17 +178,21 @@ impl App { 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) .begin_symbol(Some("↑")) .end_symbol(Some("↓")); - frame.render_stateful_widget( - scrollbar, - area[1], - &mut state - .scroll_state - .viewport_content_length(area[0].height as usize), - ); + frame.render_stateful_widget(scrollbar, area[1], &mut state.scroll_state); } fn handle_events(&mut self) -> io::Result<()> { diff --git a/src/ui/components/monitor_list.rs b/src/ui/components/monitor_list.rs index df9f28c..ee36f8a 100644 --- a/src/ui/components/monitor_list.rs +++ b/src/ui/components/monitor_list.rs @@ -18,10 +18,10 @@ const MAX_NAME_LENGTH: usize = 30; pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut DashboardViewState) { 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 { - state.scroll_state = state.scroll_state.position(total_lenght - available_height); + if state.scroll_state.get_position() > max_scroll { + state.scroll_state = state.scroll_state.position(max_scroll); } let scroll_pos = state.scroll_state.get_position();