Fix spaced columns
This commit is contained in:
@@ -37,9 +37,19 @@ pub struct SpacedColumns(pub Vec<(LayoutItem, Box<dyn Widget>)>);
|
|||||||
|
|
||||||
impl Widget for SpacedColumns {
|
impl Widget for SpacedColumns {
|
||||||
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::Columns {
|
let mut alloc = scope.rect.allocate(&crate::layout::LayoutItem::Columns {
|
||||||
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() {
|
||||||
@@ -49,10 +59,8 @@ impl Widget for SpacedColumns {
|
|||||||
let rect = &mut alloc.widgets[i];
|
let rect = &mut alloc.widgets[i];
|
||||||
|
|
||||||
for i in 0..rect.height {
|
for i in 0..rect.height {
|
||||||
scope.draw_text((rect.x - 1, i), "│");
|
scope.draw_text((rect.x - 2, i), "│");
|
||||||
}
|
}
|
||||||
rect.x += 1;
|
|
||||||
rect.width -= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alloc.draw(i, &*item.1);
|
alloc.draw(i, &*item.1);
|
||||||
|
|||||||
+2
-6
@@ -1,11 +1,7 @@
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
use pulse_ui::{
|
use pulse_ui::{
|
||||||
App,
|
App, layout::{LayoutItem, layout}, state::{Refresh, State}, unit::Size, widget::{outline::Outline, spaced::{SpacedColumns, SpacedRows}},
|
||||||
layout::{LayoutItem, layout},
|
|
||||||
state::{Refresh, State},
|
|
||||||
unit::Size,
|
|
||||||
widget::{outline::Outline, spaced::SpacedRows},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct PulseTradeApp {
|
pub struct PulseTradeApp {
|
||||||
@@ -39,7 +35,7 @@ impl App for PulseTradeApp {
|
|||||||
|
|
||||||
layout.draw(
|
layout.draw(
|
||||||
0,
|
0,
|
||||||
SpacedRows(vec![
|
SpacedColumns(vec![
|
||||||
(LayoutItem::Widget(Size::Flex(1)), Box::new("one")),
|
(LayoutItem::Widget(Size::Flex(1)), Box::new("one")),
|
||||||
(LayoutItem::Widget(Size::Flex(1)), Box::new("two")),
|
(LayoutItem::Widget(Size::Flex(1)), Box::new("two")),
|
||||||
(LayoutItem::Widget(Size::Flex(1)), Box::new("three")),
|
(LayoutItem::Widget(Size::Flex(1)), Box::new("three")),
|
||||||
|
|||||||
Reference in New Issue
Block a user