use ratatui::layout::{Constraint, Direction, Layout, Rect};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct McLayout {
pub inbox: Rect,
pub analytics: Rect,
pub activity: Rect,
pub schedule: Rect,
pub help_bar: Rect,
}
pub fn compute(area: Rect) -> McLayout {
let (panels_area, help_bar) = split_help_bar(area);
let cols = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(40), Constraint::Percentage(60)])
.split(panels_area);
let left_rows = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Percentage(22),
Constraint::Percentage(48),
Constraint::Percentage(30),
])
.split(cols[0]);
McLayout {
inbox: left_rows[0],
activity: left_rows[1],
schedule: left_rows[2],
analytics: cols[1],
help_bar,
}
}
fn split_help_bar(area: Rect) -> (Rect, Rect) {
if area.height < 2 {
let empty = Rect { height: 0, ..area };
return (area, empty);
}
let panels = Rect {
height: area.height - 1,
..area
};
let help_bar = Rect {
x: area.x,
y: area.y + area.height - 1,
width: area.width,
height: 1,
};
(panels, help_bar)
}