Added Frame layout, and fix outline

This commit is contained in:
2026-07-14 22:17:41 +02:00
parent c758f55fc6
commit 62511d2101
3 changed files with 32 additions and 5 deletions
+16
View File
@@ -4,6 +4,7 @@ use crate::unit::{Rect, Size};
pub enum LayoutItem { pub enum LayoutItem {
Rows { unit: Size, items: Vec<LayoutItem> }, Rows { unit: Size, items: Vec<LayoutItem> },
Columns { unit: Size, items: Vec<LayoutItem> }, Columns { unit: Size, items: Vec<LayoutItem> },
Frame { padding: u16, item: Box<LayoutItem> },
Widget(Size), Widget(Size),
} }
@@ -63,6 +64,20 @@ impl LayoutItem {
} }
} }
Self::Frame { padding, item } => {
frame.push(*alloc);
let mut item_alloc = alloc.clone();
item_alloc.width -= padding * 2;
item_alloc.height -= padding * 2;
item_alloc.x += padding;
item_alloc.y += padding;
item.allocate(&item_alloc, frame, widgets);
}
Self::Widget(_) => { Self::Widget(_) => {
widgets.push(*alloc); widgets.push(*alloc);
} }
@@ -74,6 +89,7 @@ impl LayoutItem {
Self::Rows { unit, .. } => unit, Self::Rows { unit, .. } => unit,
Self::Columns { unit, .. } => unit, Self::Columns { unit, .. } => unit,
Self::Widget(unit) => unit, Self::Widget(unit) => unit,
Self::Frame { item, .. } => item.get_size(),
} }
} }
} }
+1 -1
View File
@@ -13,7 +13,7 @@ impl Widget for Outline {
); );
scope.draw_text( scope.draw_text(
(0, scope.rect.height), (0, scope.rect.height - 1),
"-".repeat(scope.rect.width as usize), "-".repeat(scope.rect.width as usize),
); );
} }
+15 -4
View File
@@ -1,7 +1,11 @@
use std::any::Any; use std::any::Any;
use pulse_ui::{ use pulse_ui::{
App, layout::{LayoutItem, layout}, state::State, unit::Size, widget::outline::Outline, App,
layout::{LayoutItem, layout},
state::State,
unit::Size,
widget::outline::Outline,
}; };
pub struct PulseTradeApp { pub struct PulseTradeApp {
@@ -17,14 +21,21 @@ impl App for PulseTradeApp {
async fn layout(&self) -> pulse_ui::layout::LayoutItem { async fn layout(&self) -> pulse_ui::layout::LayoutItem {
layout(vec![ layout(vec![
LayoutItem::Widget(Size::Flex(1)), LayoutItem::Frame {
LayoutItem::Widget(Size::Flex(1)), padding: 1,
item: Box::new(LayoutItem::Widget(Size::Flex(1))),
},
LayoutItem::Frame {
padding: 1,
item: Box::new(LayoutItem::Widget(Size::Flex(1))),
},
]) ])
} }
async fn render(&mut self, layout: pulse_ui::layout::Allocation) { async fn render(&mut self, layout: pulse_ui::layout::Allocation) {
layout.draw(1, "Yo"); layout.draw(1, "Yo");
layout.draw_frame(0, Outline); layout.draw_frame(1, Outline);
layout.draw_frame(2, Outline);
} }
} }