diff --git a/crates/tek_core/src/tui/tui_layout.rs b/crates/tek_core/src/tui/tui_layout.rs index 80e9ab16..b952385d 100644 --- a/crates/tek_core/src/tui/tui_layout.rs +++ b/crates/tek_core/src/tui/tui_layout.rs @@ -51,17 +51,33 @@ impl<'a> Render for Split<'a, Tui> { impl<'a> Split<'a, Tui> { pub fn render_areas (&self, to: &mut Tui) -> Usually<(Rect, Vec)> { + // 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)) } }