mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
fixme: very bad Split implementation
This commit is contained in:
parent
4320e6f6b4
commit
fe09536a45
1 changed files with 27 additions and 5 deletions
|
|
@ -51,17 +51,33 @@ impl<'a> Render<Tui> for Split<'a, Tui> {
|
||||||
|
|
||||||
impl<'a> Split<'a, Tui> {
|
impl<'a> Split<'a, Tui> {
|
||||||
pub fn render_areas (&self, to: &mut Tui) -> Usually<(Rect, Vec<Rect>)> {
|
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 Rect { mut x, mut y, mut width, mut height } = to.area();
|
||||||
let mut areas = vec![];
|
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() {
|
for (index, item) in self.items.0.iter().enumerate() {
|
||||||
if width == 0 || height == 0 {
|
match self.direction {
|
||||||
break
|
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 result = item.render(to.with_area(x, y, width, height))?.unwrap_or(Rect::default());
|
||||||
let Rect { width: w, height: h, .. } = result;
|
let Rect { width: w, height: h, .. } = result;
|
||||||
match self.direction {
|
match self.direction {
|
||||||
Direction::Down => { y += h; height = height.saturating_sub(h); },
|
Direction::Down => {
|
||||||
Direction::Right => { x += w; width = width.saturating_sub(w); },
|
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!()
|
_ => unimplemented!()
|
||||||
};
|
};
|
||||||
areas.push(result);
|
areas.push(result);
|
||||||
|
|
@ -69,6 +85,12 @@ impl<'a> Split<'a, Tui> {
|
||||||
Corners(Style::default().green().not_dim()).draw(to.with_rect(result))?;
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue