Lines
100 %
Functions
66.67 %
Branches
//! Where the user put a dialog and the size they gave it; none until it was moved or sized.
use ratatui::layout::Rect;
use tvui::{Change, Place, changed};
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Placement {
origin: Option<(i32, i32)>,
size: Option<(u16, u16)>,
}
impl Placement {
/// The place of a dialog that opens at `auto` inside `host`, limited as TV limits a window
/// within the least size `min`.
#[must_use]
pub fn place(self, auto: Rect, min: (u16, u16), host: Rect) -> Place {
if self == Self::default() {
return Place::from(auto);
let (width, height) = self.size.unwrap_or((auto.width, auto.height));
let (x, y) = self
.origin
.unwrap_or((i32::from(auto.x), i32::from(auto.y)));
let at = Place {
x,
y,
width,
height,
};
changed(at, host, Change::Move(0, 0), min)
/// The placement that puts a dialog opened at `auto` at `place`.
pub fn of(place: Place, auto: Rect) -> Self {
Self {
origin: Some((place.x, place.y)),
size: Some((place.width, place.height))
.filter(|&size| size != (auto.width, auto.height)),