Fixing group height
This commit is contained in:
parent
ba8a658d6e
commit
063775425a
1 changed files with 44 additions and 17 deletions
|
|
@ -17,41 +17,68 @@ const STATUS_LINE_LENGTH: usize = 100;
|
||||||
const MAX_NAME_LENGTH: usize = 30;
|
const MAX_NAME_LENGTH: usize = 30;
|
||||||
|
|
||||||
pub fn render_monitor_list(frame: &mut Frame, area: Rect, state: &DashboardViewState) {
|
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() {
|
for (i, (group, &group_area)) in state.groups.iter().zip(group_areas.iter()).enumerate() {
|
||||||
if i < group_areas.len() {
|
render_group(frame, group_area, group, i == 0);
|
||||||
render_group(frame, group_areas[i], group, i == 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_groups(area: Rect, group_count: usize) -> Vec<Rect> {
|
fn layout_groups(area: Rect, groups: &[GroupViewState]) -> Vec<Rect> {
|
||||||
if group_count == 0 {
|
let total_lines: usize = groups.iter().map(|g| g.monitors.len() + 1).sum();
|
||||||
return vec![];
|
|
||||||
|
if total_lines == 0 {
|
||||||
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
let height_per_group = (area.height as usize / group_count).max(3);
|
let content_height = area.height.saturating_sub(2);
|
||||||
let mut current_y = area.y;
|
let line_height = content_height as usize / total_lines;
|
||||||
|
|
||||||
|
let mut current_y = area.y + 1;
|
||||||
let mut areas = Vec::new();
|
let mut areas = Vec::new();
|
||||||
|
|
||||||
for _ in 0..group_count {
|
for group in groups {
|
||||||
if current_y + height_per_group as u16 > area.y + area.height {
|
let group_lines = group.monitors.len() + 1;
|
||||||
break;
|
let group_height = (group_lines + line_height).max(1);
|
||||||
}
|
|
||||||
|
|
||||||
areas.push(Rect {
|
areas.push(Rect {
|
||||||
x: area.x,
|
x: area.x,
|
||||||
y: current_y,
|
y: current_y,
|
||||||
width: area.width,
|
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
|
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) {
|
fn render_group(frame: &mut Frame, area: Rect, group: &GroupViewState, is_first: bool) {
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue