Center
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
use crate::widget::Widget;
|
||||||
|
|
||||||
|
pub struct Center(pub String);
|
||||||
|
|
||||||
|
impl Widget for Center {
|
||||||
|
fn render(&self, scope: &mut crate::render::RenderScope) {
|
||||||
|
let mut width = 0;
|
||||||
|
let mut height = 0;
|
||||||
|
|
||||||
|
for line in self.0.lines() {
|
||||||
|
height += 1;
|
||||||
|
width = width.max(line.len() as u16);
|
||||||
|
}
|
||||||
|
|
||||||
|
let x = (scope.rect.width - width) / 2;
|
||||||
|
let y = (scope.rect.height - height) / 2;
|
||||||
|
|
||||||
|
scope.draw_text((x, y), &self.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod center;
|
||||||
pub mod outline;
|
pub mod outline;
|
||||||
pub mod spaced;
|
pub mod spaced;
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -43,7 +43,10 @@ impl App for PulseTradeApp {
|
|||||||
(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")),
|
||||||
(LayoutItem::Widget(Size::Flex(1)), Box::new(self.count.display().await)),
|
(
|
||||||
|
LayoutItem::Widget(Size::Flex(1)),
|
||||||
|
Box::new(self.count.display().await),
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user