mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
refactor: device abstraction, layout components
This commit is contained in:
parent
d330d31ce4
commit
788dc1ccde
21 changed files with 1144 additions and 1166 deletions
37
src/layout.rs
Normal file
37
src/layout.rs
Normal 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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue