1use ratatui::layout::Rect;
4use tvui::{Change, Place, changed};
5
6#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
7pub struct Placement {
8 origin: Option<(i32, i32)>,
9 size: Option<(u16, u16)>,
10}
11
12impl Placement {
13 #[must_use]
16 pub fn place(self, auto: Rect, min: (u16, u16), host: Rect) -> Place {
17 if self == Self::default() {
18 return Place::from(auto);
19 }
20 let (width, height) = self.size.unwrap_or((auto.width, auto.height));
21 let (x, y) = self
22 .origin
23 .unwrap_or((i32::from(auto.x), i32::from(auto.y)));
24 let at = Place {
25 x,
26 y,
27 width,
28 height,
29 };
30 changed(at, host, Change::Move(0, 0), min)
31 }
32
33 #[must_use]
35 pub fn of(place: Place, auto: Rect) -> Self {
36 Self {
37 origin: Some((place.x, place.y)),
38 size: Some((place.width, place.height))
39 .filter(|&size| size != (auto.width, auto.height)),
40 }
41 }
42}