Working scrollbar

This commit is contained in:
Marco De Araujo 2026-01-10 11:19:19 -04:00
parent df1d1dddc6
commit 000e31a14f
4 changed files with 58 additions and 26 deletions

View file

@ -37,7 +37,7 @@ pub struct DashboardViewState {
pub error_message: Option<String>,
pub auto_refresh_interval: u32,
pub scroll_state: ScrollbarState,
content_length: usize,
total_length: usize,
}
impl DashboardViewState {
@ -50,7 +50,7 @@ impl DashboardViewState {
error_message: None,
auto_refresh_interval: 300,
scroll_state: ScrollbarState::new(0),
content_length: 0,
total_length: 0,
}
}
@ -64,10 +64,10 @@ impl DashboardViewState {
});
}
let content_length = groups
let total_length: usize = groups
.iter()
.map(|g| g.monitors.len() + BORDER_LINES_VIEW)
.sum::<usize>();
.sum();
Self {
title: data.title,
@ -76,17 +76,21 @@ impl DashboardViewState {
is_loading: false,
error_message: None,
auto_refresh_interval: data.auto_refresh_interval.max(30),
scroll_state: ScrollbarState::new(content_length.saturating_sub(1)),
content_length,
scroll_state: ScrollbarState::new(total_length.saturating_sub(1)),
total_length,
}
}
pub fn get_total_lenght(&self) -> usize {
self.total_length
}
pub fn get_all_monitors(&self) -> Vec<&MonitorViewState> {
self.groups.iter().flat_map(|g| g.monitors.iter()).collect()
}
pub fn show_vertical_scrollbar(&self, height: u16) -> bool {
height < self.content_length as u16
pub fn show_vertical_scrollbar(&self, available_height: u16) -> bool {
self.total_length as u16 > available_height
}
}