mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: Content and Widget traits
This commit is contained in:
parent
5fc7da3aca
commit
b944dd5f9e
13 changed files with 209 additions and 36 deletions
|
|
@ -1,23 +1,53 @@
|
|||
use tek_core::*;
|
||||
use tek_core::jack::*;
|
||||
|
||||
pub fn main () -> Usually<()> {
|
||||
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Demo {
|
||||
pub struct Demo<E: Engine> {
|
||||
index: usize,
|
||||
items: Vec<Box<dyn Component<Tui>>>
|
||||
items: Vec<Box<dyn Component<E>>>
|
||||
}
|
||||
|
||||
impl Demo {
|
||||
impl Demo<Tui> {
|
||||
fn new () -> Self {
|
||||
let items = vec![];
|
||||
let mut items: Vec<Box<dyn Component<Tui>>> = vec![];
|
||||
items.push(Box::new(tek_sequencer::TransportPlayPauseButton {
|
||||
value: Some(TransportState::Stopped),
|
||||
focused: true
|
||||
}));
|
||||
items.push(Box::new(tek_sequencer::TransportPlayPauseButton {
|
||||
value: Some(TransportState::Rolling),
|
||||
focused: false
|
||||
}));
|
||||
Self { index: 0, items }
|
||||
}
|
||||
fn content <'a> (&'a self) -> impl Layout<Tui> + 'a {
|
||||
Align::Center(Layers(&[
|
||||
&Outset::WH(2, 1, FillBg(Color::Rgb(0,128,128))),
|
||||
&Layers(&[
|
||||
&"---------",
|
||||
&Align::Center("...")
|
||||
])
|
||||
]))
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Demo {
|
||||
impl Layout<Tui> for Demo<Tui> {
|
||||
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
self.content().layout(area)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render<Tui> for Demo<Tui> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
self.content().render(to)
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Demo<Tui> {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
key!(KeyCode::PageUp) => {
|
||||
|
|
@ -36,15 +66,3 @@ impl Handle<Tui> for Demo {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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