Fix spaced rows

This commit is contained in:
2026-07-15 08:52:39 +02:00
parent 88e5d69087
commit c503e8d583
2 changed files with 18 additions and 6 deletions
+6 -1
View File
@@ -7,6 +7,7 @@ pub enum LayoutItem {
Frame { padding: u16, item: Box<LayoutItem> },
Widget(Size),
Spacing(Size),
}
#[derive(Debug, Clone)]
@@ -82,6 +83,10 @@ impl LayoutItem {
Self::Widget(_) => {
full_alloc.widgets.push(*alloc);
}
Self::Spacing(_) => {
full_alloc.frame.push(*alloc);
}
}
}
@@ -89,7 +94,7 @@ impl LayoutItem {
match self {
Self::Rows { unit, .. } => unit,
Self::Columns { unit, .. } => unit,
Self::Widget(unit) => unit,
Self::Widget(unit) | Self::Spacing(unit) => unit,
Self::Frame { item, .. } => item.get_size(),
}
}
+12 -5
View File
@@ -4,9 +4,19 @@ pub struct SpacedRows(pub Vec<(LayoutItem, Box<dyn Widget>)>);
impl Widget for SpacedRows {
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 {
unit: Percent(100),
items: self.0.iter().map(|v| v.0.clone()).collect(),
items,
});
for i in 0..alloc.widgets.len() {
@@ -15,10 +25,7 @@ impl Widget for SpacedRows {
if i > 0 {
let rect = &mut alloc.widgets[i];
scope.draw_text((0, rect.y - 1), "─".repeat(rect.width as usize));
rect.y += 1;
rect.height -= 1;
scope.draw_text((0, rect.y - 2), "─".repeat(rect.width as usize));
}
alloc.draw(i, &*item.1);