Dynamic and End aling
This commit is contained in:
@@ -18,3 +18,22 @@ impl Widget for Center {
|
||||
scope.draw_text((x, y), &self.0);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct End(pub String);
|
||||
|
||||
impl Widget for End {
|
||||
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;
|
||||
let y = scope.rect.height - height;
|
||||
|
||||
scope.draw_text((x, y), &self.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
use crate::{unit::Rect, widget::Widget};
|
||||
|
||||
pub struct Dynamic(pub fn(Rect) -> Box<dyn Widget>);
|
||||
|
||||
impl Widget for Dynamic {
|
||||
fn render(&self, scope: &mut crate::render::RenderScope) {
|
||||
(self.0)(scope.rect).render(scope);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod center;
|
||||
pub mod align;
|
||||
pub mod outline;
|
||||
pub mod spaced;
|
||||
pub mod dynamic;
|
||||
|
||||
use crate::render::RenderScope;
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ use pulse_ui::{
|
||||
state::{Refresh, State},
|
||||
unit::Size,
|
||||
widget::{
|
||||
center::Center,
|
||||
align::Center,
|
||||
outline::{Outline, VLine},
|
||||
spaced::{SpacedColumns, SpacedRows},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user