mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: component playground; Align primitive
This commit is contained in:
parent
4cca03352a
commit
5fc7da3aca
12 changed files with 181 additions and 42 deletions
9
crates/tek_test/Cargo.toml
Normal file
9
crates/tek_test/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "tek_test"
|
||||
edition = "2021"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
tek_core = { path = "../tek_core" }
|
||||
tek_mixer = { path = "../tek_mixer" }
|
||||
tek_sequencer = { path = "../tek_sequencer" }
|
||||
50
crates/tek_test/src/main.rs
Normal file
50
crates/tek_test/src/main.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use tek_core::*;
|
||||
|
||||
pub fn main () -> Usually<()> {
|
||||
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Demo {
|
||||
index: usize,
|
||||
items: Vec<Box<dyn Component<Tui>>>
|
||||
}
|
||||
|
||||
impl Demo {
|
||||
fn new () -> Self {
|
||||
let items = vec![];
|
||||
Self { index: 0, items }
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Demo {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
key!(KeyCode::PageUp) => {
|
||||
self.index = (self.index + 1) % self.items.len();
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::PageDown) => {
|
||||
self.index = if self.index > 1 {
|
||||
self.index - 1
|
||||
} else {
|
||||
self.items.len() - 1
|
||||
};
|
||||
Ok(Some(true))
|
||||
},
|
||||
_ => Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout<Tui> for Demo {
|
||||
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Align::Center(self.items[self.index]).layout(area)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render<Tui> for Demo {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
Align::Center(self.items[self.index]).render(to)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue