diff --git a/src/ui/components/monitor_list.rs b/src/ui/components/monitor_list.rs index ee36f8a..db0be1d 100644 --- a/src/ui/components/monitor_list.rs +++ b/src/ui/components/monitor_list.rs @@ -28,6 +28,7 @@ pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut Dashb let mut current_y = area.y as usize; let mut rendered_height = 0; let mut lines_skipped = 0; + let half = state.get_total_lenght().saturating_div(2); for (i, group) in state.groups.iter().enumerate() { let group_height = group.monitors.len() + BORDER_LINES_VIEW; @@ -55,7 +56,7 @@ pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut Dashb main_frame, group_area, group, - i == 0 && lines_skipped >= scroll_pos, + half > rendered_height , ); current_y += visible_height; @@ -64,7 +65,7 @@ pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut Dashb } } -fn render_group(frame: &mut Frame, area: Rect, group: &GroupViewState, is_first: bool) { +fn render_group(frame: &mut Frame, area: Rect, group: &GroupViewState, is_first_half: bool) { let chunks = Layout::default() .direction(Direction::Vertical) .margin(0) @@ -84,11 +85,7 @@ fn render_group(frame: &mut Frame, area: Rect, group: &GroupViewState, is_first: ]); let title_block = Block::default() - .borders(if is_first { - Borders::TOP | Borders::LEFT | Borders::RIGHT - } else { - Borders::ALL - }) + .borders(Borders::ALL) .border_style(Style::default().fg(Color::Blue)) .title(group_title) .title_alignment(Alignment::Left); @@ -96,13 +93,24 @@ fn render_group(frame: &mut Frame, area: Rect, group: &GroupViewState, is_first: frame.render_widget(title_block, chunks[0]); if !group.monitors.is_empty() { - render_monitor_table(frame, chunks[1], &group.monitors); + render_monitor_table(frame, chunks[1], &group.monitors, is_first_half); } } -fn render_monitor_table(frame: &mut Frame, area: Rect, monitors: &Vec) { +fn render_monitor_table( + frame: &mut Frame, + area: Rect, + monitors: &Vec, + is_first_half: bool, +) { let max_items = area.height as usize; let items_to_show = min(monitors.len(), max_items); + let index = monitors.len().saturating_sub(max_items.saturating_sub(2)); // 2 = Table header + botton + let monitors = if is_first_half { + &monitors[index..].to_vec() + } else { + monitors + }; let header_cells = vec![ "".to_string(),