use ratatui::layout::{Constraint, Direction, Layout, Rect};
#[derive(Clone, Copy)]
pub struct AppLayout {
pub top_bar: Rect,
pub scrollback: Rect,
pub status_bar: Rect,
}
impl AppLayout {
pub fn compute(area: Rect) -> Self {
let cols = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(1), Constraint::Min(0), Constraint::Length(1), ])
.split(area);
Self {
top_bar: cols[0],
scrollback: cols[1],
status_bar: cols[2],
}
}
}
pub fn centered_rect(percent_x: u16, percent_y: u16, area: Rect) -> Rect {
let popup_width = area.width * percent_x / 100;
let popup_height = area.height * percent_y / 100;
let x = area.x + (area.width.saturating_sub(popup_width)) / 2;
let y = area.y + (area.height.saturating_sub(popup_height)) / 2;
Rect::new(x, y, popup_width, popup_height)
}