refactor: device abstraction, layout components

This commit is contained in:
🪞👃🪞 2024-06-12 16:55:57 +03:00
parent d330d31ce4
commit 788dc1ccde
21 changed files with 1144 additions and 1166 deletions

37
src/layout.rs Normal file
View file

@ -0,0 +1,37 @@
use crate::prelude::*;
pub struct Rows(pub Vec<Box<dyn Device>>);
pub struct Columns(pub Vec<Box<dyn Device>>);
impl Device for Rows {
fn handle (&mut self, event: &EngineEvent) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn render (&self, buf: &mut Buffer, area: Rect) {
for i in 0..3 {
self.0[i].render(buf, Rect {
x: area.x,
y: area.height / 3 * i as u16,
width: area.width,
height: area.height / 3
})
}
}
}
impl Device for Columns {
fn handle (&mut self, event: &EngineEvent) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn render (&self, buf: &mut Buffer, area: Rect) {
for i in 0..3 {
self.0[i].render(buf, Rect {
x: area.width / 3 * i as u16,
y: area.y,
width: area.width / 3,
height: area.height
})
}
}
}