use crate::core::*; pub struct Stack<'a>(pub &'a[Box]); impl<'a> Render for Stack<'a> { fn render (&self, buf: &mut Buffer, area: Rect) -> Usually { let mut area2 = area.clone(); for layer in self.0.iter() { area2 = layer.render(buf, area2)?; } Ok(area) } } pub struct Column(pub Vec>); pub struct Row(pub Vec>); impl Column { pub fn new (items: Vec>) -> Self { Self(items) } pub fn draw (buf: &mut Buffer, area: Rect, items: &[impl Render], gap: i16) -> Usually<(Rect, Vec)> { let mut w = 0u16; let mut h = 0u16; let mut rects = vec![]; for (_i, device) in items.iter().enumerate() { let y = area.y + h; let rect = Rect { x: area.x, y, width: area.width, height: area.height - h }; let result = device.render(buf, rect)?; rects.push(result); w = w.max(result.width); h = ((h + result.height) as i16 + gap).max(0) as u16; } Ok((Rect { x: area.x, y: area.y, width: w, height: h }, rects)) } } impl Render for Column { fn render (&self, buf: &mut Buffer, area: Rect) -> Usually { Ok(Column::draw(buf, area, &self.0, 0)?.0) } } impl Row { pub fn new (items: Vec>) -> Self { Self(items) } pub fn draw (buf: &mut Buffer, area: Rect, items: &[impl Render], gap: i16) -> Usually<(Rect, Vec)> { let mut w = 0u16; let mut h = 0u16; let mut rects = vec![]; for (_i, device) in items.iter().enumerate() { let x = area.x + w; let rect = Rect { x, y: area.y, width: area.width - w, height: area.height }; let result = device.render(buf, rect)?; rects.push(result); w = ((w + result.width) as i16 + gap).max(0) as u16; h = h.max(result.height); } Ok((Rect { x: area.x, y: area.y, width: w, height: h }, rects)) } } impl Render for Row { fn render (&self, buf: &mut Buffer, area: Rect) -> Usually { Ok(Row::draw(buf, area, &self.0, 0)?.0) } }