54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
|
|
|
pub struct AppLayout {
|
|
pub header: Rect,
|
|
pub main: Rect,
|
|
pub sidebar: Rect,
|
|
pub footer: Rect,
|
|
}
|
|
|
|
impl AppLayout {
|
|
pub fn new(area: Rect) -> Self {
|
|
let vertical = Layout::default()
|
|
.direction(Direction::Vertical)
|
|
.constraints([
|
|
Constraint::Length(3),
|
|
Constraint::Min(10),
|
|
Constraint::Length(3),
|
|
])
|
|
.split(area);
|
|
|
|
let horizontal = Layout::default()
|
|
.direction(Direction::Horizontal)
|
|
.constraints([Constraint::Percentage(70), Constraint::Percentage(30)])
|
|
.split(vertical[1]);
|
|
|
|
Self {
|
|
header: vertical[0],
|
|
main: horizontal[0],
|
|
sidebar: horizontal[1],
|
|
footer: vertical[2],
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn centered_rect(percent_x: u16, percent_y: u16, area: Rect) -> Rect {
|
|
let vertical = Layout::default()
|
|
.direction(Direction::Vertical)
|
|
.constraints([
|
|
Constraint::Percentage((100 - percent_y) / 2),
|
|
Constraint::Percentage(percent_y),
|
|
Constraint::Percentage((100 - percent_y) / 2),
|
|
])
|
|
.split(area);
|
|
|
|
Layout::default()
|
|
.direction(Direction::Horizontal)
|
|
.constraints([
|
|
Constraint::Percentage((100 - percent_x) / 2),
|
|
Constraint::Percentage(percent_x),
|
|
Constraint::Percentage((100 - percent_x) / 2),
|
|
])
|
|
.split(vertical[1])[1]
|
|
}
|