Dynamic and End aling

This commit is contained in:
2026-07-15 10:04:15 +02:00
parent 6283ff8f91
commit 42284ac748
4 changed files with 31 additions and 2 deletions
@@ -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);
}
}
+9
View File
@@ -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);
}
}
+2 -1
View File
@@ -1,6 +1,7 @@
pub mod center;
pub mod align;
pub mod outline;
pub mod spaced;
pub mod dynamic;
use crate::render::RenderScope;