fixme: very bad Split implementation

This commit is contained in:
🪞👃🪞 2024-09-06 18:20:02 +03:00
parent 4320e6f6b4
commit fe09536a45

View file

@ -51,17 +51,33 @@ impl<'a> Render<Tui> for Split<'a, Tui> {
impl<'a> Split<'a, Tui> {
pub fn render_areas (&self, to: &mut Tui) -> Usually<(Rect, Vec<Rect>)> {
// FIXME very shitty code
let Rect { mut x, mut y, mut width, mut height } = to.area();
let mut areas = vec![];
match self.direction {
Direction::Down => { width = 0 },
Direction::Right => { height = 0 },
_ => unimplemented!()
}
for (index, item) in self.items.0.iter().enumerate() {
if width == 0 || height == 0 {
break
match self.direction {
Direction::Down => { if height == 0 { break } },
Direction::Right => { if width == 0 { break } },
_ => unimplemented!()
}
let result = item.render(to.with_area(x, y, width, height))?.unwrap_or(Rect::default());
let Rect { width: w, height: h, .. } = result;
match self.direction {
Direction::Down => { y += h; height = height.saturating_sub(h); },
Direction::Right => { x += w; width = width.saturating_sub(w); },
Direction::Down => {
y += h;
height = height.saturating_sub(h);
width = width.max(w);
},
Direction::Right => {
x += w;
width = width.saturating_sub(w);
height = height.max(h);
},
_ => unimplemented!()
};
areas.push(result);
@ -69,6 +85,12 @@ impl<'a> Split<'a, Tui> {
Corners(Style::default().green().not_dim()).draw(to.with_rect(result))?;
}
}
Ok((to.area, areas))
let area = match self.direction {
Direction::Down => Rect { x: to.area.x, y: to.area.y, width, height: y },
Direction::Right => Rect { x: to.area.x, y: to.area.y, width: x, height },
_ => unimplemented!()
};
//panic!("{:?}", Rect { x: to.area.x, y: to.area.y, width: x, height });
Ok((Rect { x, y, width, height }, areas))
}
}