use ratatui::layout::Rect;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Breakpoint {
Compact,
Normal,
Wide,
}
#[must_use]
pub fn breakpoint(area: Rect) -> Breakpoint {
if area.width >= 120 && area.height >= 32 {
Breakpoint::Wide
} else if area.width >= 96 && area.height >= 24 {
Breakpoint::Normal
} else {
Breakpoint::Compact
}
}
#[must_use]
pub fn centered(area: Rect, width: u16, height: u16) -> Rect {
let width = width.min(area.width);
let height = height.min(area.height);
Rect {
x: area.x + (area.width - width) / 2,
y: area.y + (area.height - height) / 2,
width,
height,
}
}
#[must_use]
pub fn padded(area: Rect, horizontal: u16, vertical: u16) -> Rect {
let dx = horizontal.min(area.width / 2);
let dy = vertical.min(area.height / 2);
Rect {
x: area.x + dx,
y: area.y + dy,
width: area.width - dx * 2,
height: area.height - dy * 2,
}
}