Fixing group height

This commit is contained in:
Marco De Araujo 2025-12-25 10:57:45 -04:00
parent ba8a658d6e
commit 063775425a

View file

@ -17,41 +17,68 @@ const STATUS_LINE_LENGTH: usize = 100;
const MAX_NAME_LENGTH: usize = 30;
pub fn render_monitor_list(frame: &mut Frame, area: Rect, state: &DashboardViewState) {
let group_areas = layout_groups(area, state.groups.len());
let group_areas = layout_groups(area, &state.groups);
for (i, group) in state.groups.iter().enumerate() {
if i < group_areas.len() {
render_group(frame, group_areas[i], group, i == 0);
}
for (i, (group, &group_area)) in state.groups.iter().zip(group_areas.iter()).enumerate() {
render_group(frame, group_area, group, i == 0);
}
}
fn layout_groups(area: Rect, group_count: usize) -> Vec<Rect> {
if group_count == 0 {
return vec![];
fn layout_groups(area: Rect, groups: &[GroupViewState]) -> Vec<Rect> {
let total_lines: usize = groups.iter().map(|g| g.monitors.len() + 1).sum();
if total_lines == 0 {
return Vec::new();
}
let height_per_group = (area.height as usize / group_count).max(3);
let mut current_y = area.y;
let content_height = area.height.saturating_sub(2);
let line_height = content_height as usize / total_lines;
let mut current_y = area.y + 1;
let mut areas = Vec::new();
for _ in 0..group_count {
if current_y + height_per_group as u16 > area.y + area.height {
break;
}
for group in groups {
let group_lines = group.monitors.len() + 1;
let group_height = (group_lines + line_height).max(1);
areas.push(Rect {
x: area.x,
y: current_y,
width: area.width,
height: height_per_group as u16,
height: group_height as u16,
});
current_y += height_per_group as u16;
current_y += group_height as u16;
}
areas
}
//fn layout_groups(area: Rect, group_count: usize) -> Vec<Rect> {
// if group_count == 0 {
// return vec![];
// }
//
// let height_per_group = (area.height as usize / group_count).max(3);
// let mut current_y = area.y;
// let mut areas = Vec::new();
//
// for _ in 0..group_count {
// if current_y + height_per_group as u16 > area.y + area.height {
// break;
// }
//
// areas.push(Rect {
// x: area.x,
// y: current_y,
// width: area.width,
// height: height_per_group as u16,
// });
//
// current_y += height_per_group as u16;
// }
// areas
//}
fn render_group(frame: &mut Frame, area: Rect, group: &GroupViewState, is_first: bool) {
let chunks = Layout::default()
.direction(Direction::Vertical)