Fix spaced rows
This commit is contained in:
@@ -7,6 +7,7 @@ pub enum LayoutItem {
|
|||||||
|
|
||||||
Frame { padding: u16, item: Box<LayoutItem> },
|
Frame { padding: u16, item: Box<LayoutItem> },
|
||||||
Widget(Size),
|
Widget(Size),
|
||||||
|
Spacing(Size),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -82,6 +83,10 @@ impl LayoutItem {
|
|||||||
Self::Widget(_) => {
|
Self::Widget(_) => {
|
||||||
full_alloc.widgets.push(*alloc);
|
full_alloc.widgets.push(*alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Self::Spacing(_) => {
|
||||||
|
full_alloc.frame.push(*alloc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +94,7 @@ impl LayoutItem {
|
|||||||
match self {
|
match self {
|
||||||
Self::Rows { unit, .. } => unit,
|
Self::Rows { unit, .. } => unit,
|
||||||
Self::Columns { unit, .. } => unit,
|
Self::Columns { unit, .. } => unit,
|
||||||
Self::Widget(unit) => unit,
|
Self::Widget(unit) | Self::Spacing(unit) => unit,
|
||||||
Self::Frame { item, .. } => item.get_size(),
|
Self::Frame { item, .. } => item.get_size(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,19 @@ pub struct SpacedRows(pub Vec<(LayoutItem, Box<dyn Widget>)>);
|
|||||||
|
|
||||||
impl Widget for SpacedRows {
|
impl Widget for SpacedRows {
|
||||||
fn render(&self, scope: &mut crate::render::RenderScope) {
|
fn render(&self, scope: &mut crate::render::RenderScope) {
|
||||||
|
let mut items = Vec::new();
|
||||||
|
|
||||||
|
for (i, (item, _)) in self.0.iter().enumerate() {
|
||||||
|
if i > 0 {
|
||||||
|
items.push(LayoutItem::Spacing(crate::unit::Size::Fixed(1)))
|
||||||
|
}
|
||||||
|
|
||||||
|
items.push(item.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let mut alloc = scope.rect.allocate(&crate::layout::LayoutItem::Rows {
|
let mut alloc = scope.rect.allocate(&crate::layout::LayoutItem::Rows {
|
||||||
unit: Percent(100),
|
unit: Percent(100),
|
||||||
items: self.0.iter().map(|v| v.0.clone()).collect(),
|
items,
|
||||||
});
|
});
|
||||||
|
|
||||||
for i in 0..alloc.widgets.len() {
|
for i in 0..alloc.widgets.len() {
|
||||||
@@ -15,10 +25,7 @@ impl Widget for SpacedRows {
|
|||||||
if i > 0 {
|
if i > 0 {
|
||||||
let rect = &mut alloc.widgets[i];
|
let rect = &mut alloc.widgets[i];
|
||||||
|
|
||||||
scope.draw_text((0, rect.y - 1), "─".repeat(rect.width as usize));
|
scope.draw_text((0, rect.y - 2), "─".repeat(rect.width as usize));
|
||||||
|
|
||||||
rect.y += 1;
|
|
||||||
rect.height -= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alloc.draw(i, &*item.1);
|
alloc.draw(i, &*item.1);
|
||||||
|
|||||||
Reference in New Issue
Block a user