mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: demo_bsp
This commit is contained in:
parent
3e4d75ea40
commit
950dbdfe8e
8 changed files with 154 additions and 214 deletions
|
|
@ -1,120 +0,0 @@
|
|||
use tek_core::*;
|
||||
use tek_core::jack::*;
|
||||
|
||||
fn main () -> Usually<()> {
|
||||
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct BspDemo<E: Engine>;
|
||||
|
||||
impl Content for Demo<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> dyn Render<Engine = Tui> {
|
||||
let border_style = Style::default().fg(Color::Rgb(0,0,0));
|
||||
Align::Center(Layers::new(move|add|{
|
||||
|
||||
add(&Background(Color::Rgb(0,128,128)))?;
|
||||
|
||||
add(&Outset::XY(1, 1, Stack::down(|add|{
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,96,0)))?;
|
||||
add(&Border(Square(border_style)))?;
|
||||
add(&Outset::XY(2, 1, "..."))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,64,0)))?;
|
||||
add(&Border(Lozenge(border_style)))?;
|
||||
add(&Outset::XY(4, 2, "---"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(96,64,0)))?;
|
||||
add(&Border(SquareBold(border_style)))?;
|
||||
add(&Outset::XY(6, 3, "~~~"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
Ok(())
|
||||
})).debug())?;
|
||||
|
||||
Ok(())
|
||||
|
||||
}))
|
||||
//Align::Center(Outset::X(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Stack::down(|add|{
|
||||
//add(&Outset::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Outset::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
//})))
|
||||
//}))
|
||||
//})))
|
||||
|
||||
//Align::Y(Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Outset::X(1, Align::Center(Stack::down(|add|{
|
||||
//add(&Align::X(Outset::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Outset::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
//})))?;
|
||||
//Ok(())
|
||||
//})))))
|
||||
//}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Demo<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
key!(KeyCode::PageUp) => {
|
||||
self.index = (self.index + 1) % self.items.len();
|
||||
},
|
||||
key!(KeyCode::PageDown) => {
|
||||
self.index = if self.index > 1 {
|
||||
self.index - 1
|
||||
} else {
|
||||
self.items.len() - 1
|
||||
};
|
||||
},
|
||||
_ => return Ok(None)
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
|
||||
//lisp!(CONTENT Demo (LET
|
||||
//(BORDER-STYLE (STYLE (FG (RGB 0 0 0))))
|
||||
//(BG-COLOR-0 (RGB 0 128 128))
|
||||
//(BG-COLOR-1 (RGB 128 96 0))
|
||||
//(BG-COLOR-2 (RGB 128 64 0))
|
||||
//(BG-COLOR-3 (RGB 96 64 0))
|
||||
//(CENTER (LAYERS
|
||||
//(BACKGROUND BG-COLOR-0)
|
||||
//(OUTSET-XY 1 1 (SPLIT-DOWN
|
||||
//(LAYERS (BACKGROUND BG-COLOR-1)
|
||||
//(BORDER SQUARE BORDER-STYLE)
|
||||
//(OUTSET-XY 2 1 "..."))
|
||||
//(LAYERS (BACKGROUND BG-COLOR-2)
|
||||
//(BORDER LOZENGE BORDER-STYLE)
|
||||
//(OUTSET-XY 4 2 "---"))
|
||||
//(LAYERS (BACKGROUND BG-COLOR-3)
|
||||
//(BORDER SQUARE-BOLD BORDER-STYLE)
|
||||
//(OUTSET-XY 2 1 "~~~"))))))))
|
||||
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
use tek_core::*;
|
||||
use tek_core::jack::*;
|
||||
use tek::*;
|
||||
|
||||
fn main () -> Usually<()> {
|
||||
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
|
||||
|
|
|
|||
19
crates/tek/examples/demo_bsp.rs
Normal file
19
crates/tek/examples/demo_bsp.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use tek::{core::*, layout::*, tui::*, *};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
fn main () -> Usually<()> {
|
||||
Tui::run(Arc::new(RwLock::new(BspDemo(Default::default()))))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct BspDemo<E: Engine>(std::marker::PhantomData<E>);
|
||||
|
||||
render!(<Tui>|self:BspDemo<Tui>|Fill::wh(Align::c(
|
||||
Bsp::n(Bsp::s(Bsp::e(Bsp::w("00", "11"), "22"), "33"), "44")
|
||||
)));
|
||||
|
||||
impl Handle<Tui> for BspDemo<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,18 @@
|
|||
mod audio; pub(crate) use audio::*;
|
||||
mod color; pub(crate) use color::*;
|
||||
mod command; pub(crate) use command::*;
|
||||
mod edn; pub(crate) use edn::*;
|
||||
mod engine; pub(crate) use engine::*;
|
||||
mod focus; pub(crate) use focus::*;
|
||||
mod input; pub(crate) use input::*;
|
||||
mod output; pub(crate) use output::*;
|
||||
mod perf; pub(crate) use perf::*;
|
||||
mod pitch; pub(crate) use pitch::*;
|
||||
mod space; pub(crate) use space::*;
|
||||
mod time; pub(crate) use time::*;
|
||||
pub(crate) mod audio; pub(crate) use audio::*;
|
||||
pub(crate) mod color; pub(crate) use color::*;
|
||||
pub(crate) mod command; pub(crate) use command::*;
|
||||
pub(crate) mod edn; pub(crate) use edn::*;
|
||||
pub(crate) mod engine; pub(crate) use engine::*;
|
||||
pub(crate) mod focus; pub(crate) use focus::*;
|
||||
pub(crate) mod input; pub(crate) use input::*;
|
||||
pub(crate) mod output; pub(crate) use output::*;
|
||||
pub(crate) mod perf; pub(crate) use perf::*;
|
||||
pub(crate) mod pitch; pub(crate) use pitch::*;
|
||||
pub(crate) mod space; pub(crate) use space::*;
|
||||
pub(crate) mod time; pub(crate) use time::*;
|
||||
|
||||
pub use self::{
|
||||
engine::Engine,
|
||||
input::Handle,
|
||||
output::Render
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
use crate::*;
|
||||
|
||||
#[macro_export] macro_rules! render {
|
||||
(|$self:ident:$Struct:ident$(<$($L:lifetime),*E$(,$T:ident$(:$U:path)?)*$(,)?>)?|$cb:expr) => {
|
||||
impl<E: Engine, $($($L),*$($T $(: $U)?),*)?> Render<E> for $Struct $(<$($L,)* E, $($T),*>)? {
|
||||
fn min_size (&$self, to: <E as Engine>::Size) -> Perhaps<<E as Engine>::Size> {
|
||||
$cb.min_size(to)
|
||||
}
|
||||
fn render (&$self, to: &mut <E as Engine>::Output) -> Usually<()> {
|
||||
$cb.render(to)
|
||||
}
|
||||
}
|
||||
};
|
||||
(<$E:ty>|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||
impl $(<$($L),*$($T $(: $U)?),*>)? Render<$E> for $Struct $(<$($L),*$($T),*>)? {
|
||||
fn min_size (&$self, to: <$E as Engine>::Size) -> Perhaps<<$E as Engine>::Size> {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,20 @@
|
|||
mod align; pub(crate) use align::*;
|
||||
mod bsp; pub(crate) use bsp::*;
|
||||
mod cond; pub(crate) use cond::*;
|
||||
mod fill; pub(crate) use fill::*;
|
||||
mod fixed; pub(crate) use fixed::*;
|
||||
mod inset_outset; pub(crate) use inset_outset::*;
|
||||
mod layers; pub(crate) use layers::*;
|
||||
mod measure; pub(crate) use measure::*;
|
||||
mod min_max; pub(crate) use min_max::*;
|
||||
mod push_pull; pub(crate) use push_pull::*;
|
||||
mod scroll; pub(crate) use scroll::*;
|
||||
mod shrink_grow; pub(crate) use shrink_grow::*;
|
||||
mod split; pub(crate) use split::*;
|
||||
mod stack; pub(crate) use stack::*;
|
||||
pub(crate) mod align; pub(crate) use align::*;
|
||||
pub(crate) mod bsp; pub(crate) use bsp::*;
|
||||
pub(crate) mod cond; pub(crate) use cond::*;
|
||||
pub(crate) mod fill; pub(crate) use fill::*;
|
||||
pub(crate) mod fixed; pub(crate) use fixed::*;
|
||||
pub(crate) mod inset_outset; pub(crate) use inset_outset::*;
|
||||
pub(crate) mod layers; pub(crate) use layers::*;
|
||||
pub(crate) mod measure; pub(crate) use measure::*;
|
||||
pub(crate) mod min_max; pub(crate) use min_max::*;
|
||||
pub(crate) mod push_pull; pub(crate) use push_pull::*;
|
||||
pub(crate) mod scroll; pub(crate) use scroll::*;
|
||||
pub(crate) mod shrink_grow; pub(crate) use shrink_grow::*;
|
||||
pub(crate) mod split; pub(crate) use split::*;
|
||||
pub(crate) mod stack; pub(crate) use stack::*;
|
||||
|
||||
pub use self::{
|
||||
align::*,
|
||||
bsp::*,
|
||||
fill::*,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,57 +1,3 @@
|
|||
pub(crate) use std::sync::{Arc, Mutex, RwLock};
|
||||
pub(crate) use std::sync::atomic::{Ordering, AtomicBool, AtomicUsize};
|
||||
pub(crate) use std::collections::BTreeMap;
|
||||
pub(crate) use std::marker::PhantomData;
|
||||
pub(crate) use std::thread::{spawn, JoinHandle};
|
||||
pub(crate) use std::path::PathBuf;
|
||||
pub(crate) use std::ffi::OsString;
|
||||
pub(crate) use std::time::Duration;
|
||||
pub(crate) use std::io::{Stdout, stdout};
|
||||
pub(crate) use std::error::Error;
|
||||
|
||||
pub(crate) use ratatui;
|
||||
pub(crate) use ratatui::{
|
||||
prelude::{Style, Color, Buffer},
|
||||
style::{Stylize, Modifier},
|
||||
backend::{Backend, CrosstermBackend, ClearType}
|
||||
};
|
||||
|
||||
pub(crate) use jack;
|
||||
pub(crate) use jack::{
|
||||
contrib::ClosureProcessHandler,
|
||||
Client, ProcessScope, Control, CycleTimes,
|
||||
Port, PortSpec, MidiIn, MidiOut, AudioIn, AudioOut, Unowned,
|
||||
Transport, TransportState, MidiIter, RawMidi,
|
||||
};
|
||||
|
||||
pub(crate) use midly;
|
||||
pub(crate) use midly::{
|
||||
Smf,
|
||||
MidiMessage,
|
||||
TrackEventKind,
|
||||
live::LiveEvent,
|
||||
num::u7
|
||||
};
|
||||
|
||||
pub(crate) use palette::{
|
||||
*,
|
||||
convert::*,
|
||||
okhsl::*
|
||||
};
|
||||
|
||||
pub(crate) use clap::{self, Parser};
|
||||
|
||||
pub(crate) use crossterm::{ExecutableCommand};
|
||||
pub(crate) use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen, enable_raw_mode, disable_raw_mode};
|
||||
pub(crate) use crossterm::event::{KeyCode, KeyModifiers, KeyEvent, KeyEventKind, KeyEventState};
|
||||
pub(crate) use better_panic::{Settings, Verbosity};
|
||||
|
||||
pub(crate) use atomic_float::*;
|
||||
|
||||
use std::ops::{Add, Sub, Mul, Div, Rem};
|
||||
use std::cmp::{Ord, Eq, PartialEq};
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
/// Standard result type.
|
||||
pub type Usually<T> = Result<T, Box<dyn Error>>;
|
||||
|
||||
|
|
@ -73,11 +19,74 @@ pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
|
|||
($($name:ident)*) => { $(#[cfg(test)] mod $name;)* };
|
||||
}
|
||||
|
||||
mod core; pub(crate) use core::*;
|
||||
mod layout; pub(crate) use layout::*;
|
||||
mod api; pub(crate) use api::*;
|
||||
mod tui; pub(crate) use tui::*;
|
||||
pub mod core;
|
||||
pub(crate) use core::*;
|
||||
|
||||
testmod! {
|
||||
test
|
||||
}
|
||||
pub mod layout; pub(crate)
|
||||
use layout::*;
|
||||
|
||||
pub mod api;
|
||||
pub(crate) use api::*;
|
||||
|
||||
pub mod tui;
|
||||
pub(crate) use tui::*;
|
||||
|
||||
testmod! { test }
|
||||
|
||||
pub(crate) use clap::{self, Parser};
|
||||
|
||||
pub use better_panic;
|
||||
pub(crate) use better_panic::{Settings, Verbosity};
|
||||
|
||||
pub use atomic_float;
|
||||
pub(crate) use atomic_float::*;
|
||||
|
||||
pub(crate) use std::sync::{Arc, Mutex, RwLock};
|
||||
pub(crate) use std::sync::atomic::{Ordering, AtomicBool, AtomicUsize};
|
||||
pub(crate) use std::collections::BTreeMap;
|
||||
pub(crate) use std::marker::PhantomData;
|
||||
pub(crate) use std::thread::{spawn, JoinHandle};
|
||||
pub(crate) use std::path::PathBuf;
|
||||
pub(crate) use std::ffi::OsString;
|
||||
pub(crate) use std::time::Duration;
|
||||
pub(crate) use std::io::{Stdout, stdout};
|
||||
pub(crate) use std::error::Error;
|
||||
pub(crate) use std::ops::{Add, Sub, Mul, Div, Rem};
|
||||
pub(crate) use std::cmp::{Ord, Eq, PartialEq};
|
||||
pub(crate) use std::fmt::{Debug, Display};
|
||||
|
||||
pub use crossterm;
|
||||
pub(crate) use crossterm::{ExecutableCommand};
|
||||
pub(crate) use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen, enable_raw_mode, disable_raw_mode};
|
||||
pub(crate) use crossterm::event::{KeyCode, KeyModifiers, KeyEvent, KeyEventKind, KeyEventState};
|
||||
|
||||
pub use ratatui;
|
||||
pub(crate) use ratatui::{
|
||||
prelude::{Style, Color, Buffer},
|
||||
style::{Stylize, Modifier},
|
||||
backend::{Backend, CrosstermBackend, ClearType}
|
||||
};
|
||||
|
||||
pub use jack;
|
||||
pub(crate) use jack::{
|
||||
contrib::ClosureProcessHandler,
|
||||
Client, ProcessScope, Control, CycleTimes,
|
||||
Port, PortSpec, MidiIn, MidiOut, AudioIn, AudioOut, Unowned,
|
||||
Transport, TransportState, MidiIter, RawMidi,
|
||||
};
|
||||
|
||||
pub use midly;
|
||||
pub(crate) use midly::{
|
||||
Smf,
|
||||
MidiMessage,
|
||||
TrackEventKind,
|
||||
live::LiveEvent,
|
||||
num::u7
|
||||
};
|
||||
|
||||
pub use palette;
|
||||
pub(crate) use palette::{
|
||||
*,
|
||||
convert::*,
|
||||
okhsl::*
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,21 @@
|
|||
use crate::*;
|
||||
|
||||
mod tui_input; pub(crate) use tui_input::*;
|
||||
mod tui_style; pub(crate) use tui_style::*;
|
||||
mod tui_theme; pub(crate) use tui_theme::*;
|
||||
mod tui_output; pub(crate) use tui_output::*;
|
||||
mod tui_border; pub(crate) use tui_border::*;
|
||||
mod tui_input;
|
||||
pub(crate) use tui_input::*;
|
||||
pub use tui_input::TuiInput;
|
||||
|
||||
mod tui_output;
|
||||
pub(crate) use tui_output::*;
|
||||
pub use tui_output::TuiOutput;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
mod tui_style;
|
||||
pub(crate) use tui_style::*;
|
||||
mod tui_theme;
|
||||
pub(crate) use tui_theme::*;
|
||||
mod tui_border;
|
||||
pub(crate) use tui_border::*;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue