This commit is contained in:
2026-07-14 22:08:26 +02:00
parent 809e5d1529
commit c758f55fc6
5 changed files with 33 additions and 5 deletions
+2
View File
@@ -25,6 +25,8 @@ pub trait App {
self.render(get_screen().allocate(&self.layout().await))
.await;
crossterm::execute!(std::io::stdout()).unwrap();
}
}
+7 -1
View File
@@ -66,6 +66,12 @@ impl Allocation {
widget.render(&mut scope);
scope.draw();
}
pub fn draw_frame<W: Widget>(&self, index: usize, widget: W) {
let mut scope = RenderScope::new(self.frame_alloc[index]);
widget.render(&mut scope);
scope.draw();
}
}
impl RenderScope {
@@ -89,5 +95,5 @@ impl RenderScope {
pub fn print_at(x: u16, y: u16, text: &str) {
crossterm::execute!(stdout(), crossterm::cursor::MoveTo(x, y)).unwrap();
println!("{text}");
print!("{text}");
}
+2
View File
@@ -1,3 +1,5 @@
pub mod outline;
use crate::render::RenderScope;
pub trait Widget {
+20
View File
@@ -0,0 +1,20 @@
use crate::widget::Widget;
pub struct Outline;
impl Widget for Outline {
fn render(&self, scope: &mut crate::render::RenderScope) {
scope.draw_text(0, "-".repeat(scope.rect.width as usize));
scope.draw_text((0, 1), "|\n".repeat(scope.rect.height as usize - 2));
scope.draw_text(
(scope.rect.width, 1),
"|\n".repeat(scope.rect.height as usize - 2),
);
scope.draw_text(
(0, scope.rect.height),
"-".repeat(scope.rect.width as usize),
);
}
}