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); 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 outline;
pub mod spaced; pub mod spaced;
pub mod dynamic;
use crate::render::RenderScope; use crate::render::RenderScope;
+1 -1
View File
@@ -6,7 +6,7 @@ use pulse_ui::{
state::{Refresh, State}, state::{Refresh, State},
unit::Size, unit::Size,
widget::{ widget::{
center::Center, align::Center,
outline::{Outline, VLine}, outline::{Outline, VLine},
spaced::{SpacedColumns, SpacedRows}, spaced::{SpacedColumns, SpacedRows},
}, },