diff --git a/pulse-ui/src/widget/center.rs b/pulse-ui/src/widget/align.rs similarity index 52% rename from pulse-ui/src/widget/center.rs rename to pulse-ui/src/widget/align.rs index 33ac06e..b72c7fd 100644 --- a/pulse-ui/src/widget/center.rs +++ b/pulse-ui/src/widget/align.rs @@ -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); + } +} diff --git a/pulse-ui/src/widget/dynamic.rs b/pulse-ui/src/widget/dynamic.rs new file mode 100644 index 0000000..9b76bb4 --- /dev/null +++ b/pulse-ui/src/widget/dynamic.rs @@ -0,0 +1,9 @@ +use crate::{unit::Rect, widget::Widget}; + +pub struct Dynamic(pub fn(Rect) -> Box); + +impl Widget for Dynamic { + fn render(&self, scope: &mut crate::render::RenderScope) { + (self.0)(scope.rect).render(scope); + } +} diff --git a/pulse-ui/src/widget/mod.rs b/pulse-ui/src/widget/mod.rs index d75c0e6..d1b3b3b 100644 --- a/pulse-ui/src/widget/mod.rs +++ b/pulse-ui/src/widget/mod.rs @@ -1,6 +1,7 @@ -pub mod center; +pub mod align; pub mod outline; pub mod spaced; +pub mod dynamic; use crate::render::RenderScope; diff --git a/src/main.rs b/src/main.rs index 9071d16..2ce7d3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use pulse_ui::{ state::{Refresh, State}, unit::Size, widget::{ - center::Center, + align::Center, outline::{Outline, VLine}, spaced::{SpacedColumns, SpacedRows}, },