wip: distribute layout operator parsing

This commit is contained in:
🪞👃🪞 2025-01-13 23:21:56 +01:00
parent 4af6e011b6
commit fa70a42bad
12 changed files with 150 additions and 81 deletions

View file

@ -25,7 +25,7 @@ use crate::*;
} }
/// Map EDN tokens to parameters of a given type for a given context /// Map EDN tokens to parameters of a given type for a given context
pub trait EdnProvide<'a, U> { pub trait EdnProvide<'a, U>: Sized {
fn get <S: AsRef<str>> (&'a self, _edn: &'a EdnItem<S>) -> Option<U> { fn get <S: AsRef<str>> (&'a self, _edn: &'a EdnItem<S>) -> Option<U> {
None None
} }

View file

@ -3,11 +3,12 @@
pub(crate) use std::{fmt::{Debug, Formatter, Error as FormatError}}; pub(crate) use std::{fmt::{Debug, Formatter, Error as FormatError}};
mod edn_error; pub use self::edn_error::*; mod edn_error; pub use self::edn_error::*;
mod edn_item; pub use self::edn_item::*; mod edn_item; pub use self::edn_item::*;
mod edn_iter; pub use self::edn_iter::*; mod edn_iter; pub use self::edn_iter::*;
mod edn_token; pub use self::edn_token::*; mod edn_token; pub use self::edn_token::*;
mod edn_provide; pub use self::edn_provide::*; mod edn_provide; pub use self::edn_provide::*;
mod try_from_edn; pub use self::try_from_edn::*;
#[cfg(test)] #[test] fn test_edn () -> Result<(), ParseError> { #[cfg(test)] #[test] fn test_edn () -> Result<(), ParseError> {
use EdnItem::*; use EdnItem::*;

6
edn/src/try_from_edn.rs Normal file
View file

@ -0,0 +1,6 @@
use crate::*;
pub trait TryFromEdn<'a, T>: Sized {
fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) ->
Option<Self>;
}

View file

@ -19,8 +19,8 @@ render!(TuiOut: (self: PoolView<'a>) => {
Fixed::y(1, map_south(item_offset, item_height, Tui::bg(bg, lay!( Fixed::y(1, map_south(item_offset, item_height, Tui::bg(bg, lay!(
Fill::x(Align::w(Tui::fg(fg, Tui::bold(selected, name)))), Fill::x(Align::w(Tui::fg(fg, Tui::bold(selected, name)))),
Fill::x(Align::e(Tui::fg(fg, Tui::bold(selected, length)))), Fill::x(Align::e(Tui::fg(fg, Tui::bold(selected, length)))),
Fill::x(Align::w(When(selected, Tui::bold(true, Tui::fg(TuiTheme::g(255), ""))))), Fill::x(Align::w(When::new(selected, Tui::bold(true, Tui::fg(TuiTheme::g(255), ""))))),
Fill::x(Align::e(When(selected, Tui::bold(true, Tui::fg(TuiTheme::g(255), ""))))), Fill::x(Align::e(When::new(selected, Tui::bold(true, Tui::fg(TuiTheme::g(255), ""))))),
)))) ))))
}))))) })))))
}); });

View file

@ -37,52 +37,60 @@ pub trait EdnViewData<'a, E: Output>:
match item { match item {
Nil => Box::new(()), Nil => Box::new(()),
Exp(e) => if let [head, tail @ ..] = e.as_slice() { Exp(e) => if let [head, tail @ ..] = e.as_slice() {
if let Some(builtin) = When::<_, Box<dyn Render<E>>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
if let Some(builtin) = Either::<_, Box<dyn Render<E>>, Box<dyn Render<E>>>::try_from_edn(self, head, tail) {
return builtin.boxed()
}
panic!("{item:?}");
match (head, tail) { match (head, tail) {
(Key("when"), [c, a]) => //(Key("when"), [c, a]) =>
When(self.arg(c).unwrap(), self.item(a)).boxed(), //When(self.arg(c).unwrap(), self.get_content(a)).boxed(),
(Key("either"), [c, a, b]) => //(Key("either"), [c, a, b]) =>
Either(self.arg(c).unwrap(), self.item(a), self.item(b)).boxed(), //Either(self.arg(c).unwrap(), self.get_content(a), self.get_content(b)).boxed(),
(Key("align/c"), [a]) => Align::c(self.item(a)).boxed(), (Key("align/c"), [a]) => Align::c(self.get_content(a)).boxed(),
(Key("align/x"), [a]) => Align::x(self.item(a)).boxed(), (Key("align/x"), [a]) => Align::x(self.get_content(a)).boxed(),
(Key("align/y"), [a]) => Align::y(self.item(a)).boxed(), (Key("align/y"), [a]) => Align::y(self.get_content(a)).boxed(),
(Key("align/n"), [a]) => Align::n(self.item(a)).boxed(), (Key("align/n"), [a]) => Align::n(self.get_content(a)).boxed(),
(Key("align/s"), [a]) => Align::s(self.item(a)).boxed(), (Key("align/s"), [a]) => Align::s(self.get_content(a)).boxed(),
(Key("align/e"), [a]) => Align::e(self.item(a)).boxed(), (Key("align/e"), [a]) => Align::e(self.get_content(a)).boxed(),
(Key("align/w"), [a]) => Align::w(self.item(a)).boxed(), (Key("align/w"), [a]) => Align::w(self.get_content(a)).boxed(),
(Key("align/nw"), [a]) => Align::nw(self.item(a)).boxed(), (Key("align/nw"), [a]) => Align::nw(self.get_content(a)).boxed(),
(Key("align/ne"), [a]) => Align::ne(self.item(a)).boxed(), (Key("align/ne"), [a]) => Align::ne(self.get_content(a)).boxed(),
(Key("align/sw"), [a]) => Align::sw(self.item(a)).boxed(), (Key("align/sw"), [a]) => Align::sw(self.get_content(a)).boxed(),
(Key("align/se"), [a]) => Align::se(self.item(a)).boxed(), (Key("align/se"), [a]) => Align::se(self.get_content(a)).boxed(),
(Key("bsp/a"), [a, b]) => Bsp::a(self.item(a), self.item(b),).boxed(), (Key("bsp/a"), [a, b]) => Bsp::a(self.get_content(a), self.get_content(b),).boxed(),
(Key("bsp/b"), [a, b]) => Bsp::b(self.item(a), self.item(b),).boxed(), (Key("bsp/b"), [a, b]) => Bsp::b(self.get_content(a), self.get_content(b),).boxed(),
(Key("bsp/e"), [a, b]) => Bsp::e(self.item(a), self.item(b),).boxed(), (Key("bsp/e"), [a, b]) => Bsp::e(self.get_content(a), self.get_content(b),).boxed(),
(Key("bsp/n"), [a, b]) => Bsp::n(self.item(a), self.item(b),).boxed(), (Key("bsp/n"), [a, b]) => Bsp::n(self.get_content(a), self.get_content(b),).boxed(),
(Key("bsp/s"), [a, b]) => Bsp::s(self.item(a), self.item(b),).boxed(), (Key("bsp/s"), [a, b]) => Bsp::s(self.get_content(a), self.get_content(b),).boxed(),
(Key("bsp/w"), [a, b]) => Bsp::w(self.item(a), self.item(b),).boxed(), (Key("bsp/w"), [a, b]) => Bsp::w(self.get_content(a), self.get_content(b),).boxed(),
(Key("fill/x"), [a]) => Fill::x(self.item(a)).boxed(), (Key("fill/x"), [a]) => Fill::x(self.get_content(a)).boxed(),
(Key("fill/y"), [a]) => Fill::y(self.item(a)).boxed(), (Key("fill/y"), [a]) => Fill::y(self.get_content(a)).boxed(),
(Key("fill/xy"), [a]) => Fill::xy(self.item(a)).boxed(), (Key("fill/xy"), [a]) => Fill::xy(self.get_content(a)).boxed(),
(Key("fixed/x"), [x, a]) => Fixed::x(self.arg(x).unwrap(), self.item(a)).boxed(), (Key("fixed/x"), [x, a]) => Fixed::x(self.arg(x).unwrap(), self.get_content(a)).boxed(),
(Key("fixed/y"), [y, a]) => Fixed::y(self.arg(y).unwrap(), self.item(a)).boxed(), (Key("fixed/y"), [y, a]) => Fixed::y(self.arg(y).unwrap(), self.get_content(a)).boxed(),
(Key("fixed/xy"), [x, y, a]) => Fixed::xy(self.arg(x).unwrap(), self.arg(y).unwrap(), self.item(a)).boxed(), (Key("fixed/xy"), [x, y, a]) => Fixed::xy(self.arg(x).unwrap(), self.arg(y).unwrap(), self.get_content(a)).boxed(),
(Key("max/x"), [x, a]) => Max::x(self.arg(x).unwrap(), self.item(a)).boxed(), (Key("max/x"), [x, a]) => Max::x(self.arg(x).unwrap(), self.get_content(a)).boxed(),
(Key("max/y"), [y, a]) => Max::y(self.arg(y).unwrap(), self.item(a)).boxed(), (Key("max/y"), [y, a]) => Max::y(self.arg(y).unwrap(), self.get_content(a)).boxed(),
(Key("push/x"), [x, a]) => Push::x(self.arg(x).unwrap(), self.item(a)).boxed(), (Key("push/x"), [x, a]) => Push::x(self.arg(x).unwrap(), self.get_content(a)).boxed(),
(Key("push/y"), [y, a]) => Push::y(self.arg(y).unwrap(), self.item(a)).boxed(), (Key("push/y"), [y, a]) => Push::y(self.arg(y).unwrap(), self.get_content(a)).boxed(),
(Key("pad/x"), [x, a]) => Padding::x(self.arg(x).unwrap(), self.item(a)).boxed(), (Key("pad/x"), [x, a]) => Padding::x(self.arg(x).unwrap(), self.get_content(a)).boxed(),
(Key("pad/y"), [y, a]) => Padding::y(self.arg(y).unwrap(), self.item(a)).boxed(), (Key("pad/y"), [y, a]) => Padding::y(self.arg(y).unwrap(), self.get_content(a)).boxed(),
(Key("pad/xy"), [x, y, a]) => Padding::xy(self.arg(x).unwrap(), self.arg(y).unwrap(), self.item(a)).boxed(), (Key("pad/xy"), [x, y, a]) => Padding::xy(self.arg(x).unwrap(), self.arg(y).unwrap(), self.get_content(a)).boxed(),
(Key("grow/x"), [x, a]) => Margin::x(self.arg(x).unwrap(), self.item(a)).boxed(), (Key("grow/x"), [x, a]) => Margin::x(self.arg(x).unwrap(), self.get_content(a)).boxed(),
(Key("grow/y"), [y, a]) => Margin::y(self.arg(y).unwrap(), self.item(a)).boxed(), (Key("grow/y"), [y, a]) => Margin::y(self.arg(y).unwrap(), self.get_content(a)).boxed(),
(Key("grow/xy"), [x, y, a]) => Margin::xy(self.arg(x).unwrap(), self.arg(y).unwrap(), self.item(a)).boxed(), (Key("grow/xy"), [x, y, a]) => Margin::xy(self.arg(x).unwrap(), self.arg(y).unwrap(), self.get_content(a)).boxed(),
_ => todo!("{:?} {:?}", &head, &tail) _ => todo!("{:?} {:?}", &head, &tail)
} }
@ -103,7 +111,7 @@ impl<'a, E: Output, T> EdnViewData<'a, E> for T where T:
/// Renders from EDN source and context. /// Renders from EDN source and context.
#[derive(Default)] #[derive(Default)]
pub enum EdnView<'a, E: Output, T: EdnViewData<'a, E>> { pub enum EdnView<'a, E: Output, T: EdnViewData<'a, E> + std::fmt::Debug> {
#[default] #[default]
Inert, Inert,
_Unused(PhantomData<&'a E>), _Unused(PhantomData<&'a E>),
@ -111,12 +119,21 @@ pub enum EdnView<'a, E: Output, T: EdnViewData<'a, E>> {
//render: Box<dyn Fn(&'a T)->Box<dyn Render<E> + Send + Sync + 'a> + Send + Sync + 'a> //render: Box<dyn Fn(&'a T)->Box<dyn Render<E> + Send + Sync + 'a> + Send + Sync + 'a>
Err(String) Err(String)
} }
impl<'a, E: Output, T: EdnViewData<'a, E> + std::fmt::Debug> std::fmt::Debug for EdnView<'a, E, T> {
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
Self::Inert | Self::_Unused(_) => write!(f, "EdnView::Inert"),
Self::Ok(state, view) => write!(f, "EdnView::Ok(state={state:?} view={view:?}"),
Self::Err(error) => write!(f, "EdnView::Err({error})"),
}
}
}
impl<'a, E: Output, T: EdnViewData<'a, E>> EdnView<'a, E, T> { impl<'a, E: Output, T: EdnViewData<'a, E> + std::fmt::Debug> EdnView<'a, E, T> {
pub fn from_source (state: T, source: &'a str) -> Self { pub fn from_source (state: T, source: &'a str) -> Self {
match EdnItem::read_one(&source) { match EdnItem::read_one(&source) {
Ok((layout, _)) => Self::Ok(state, layout), Ok((layout, _)) => Self::Ok(state, layout),
Err(error) => Self::Err(format!("{error}")) Err(error) => Self::Err(format!("{error} in {source}"))
} }
} }
pub fn from_items (state: T, items: Vec<EdnItem<&'a str>>) -> Self { pub fn from_items (state: T, items: Vec<EdnItem<&'a str>>) -> Self {
@ -124,14 +141,13 @@ impl<'a, E: Output, T: EdnViewData<'a, E>> EdnView<'a, E, T> {
} }
} }
impl<E: Output, T: for<'a>EdnViewData<'a, E> + Send + Sync> Content<E> for EdnView<'_, E, T> { impl<E: Output, T: for<'a>EdnViewData<'a, E> + Send + Sync + std::fmt::Debug> Content<E> for EdnView<'_, E, T> {
fn content (&self) -> impl Render<E> { fn content (&self) -> impl Render<E> {
match self { match self {
Self::Ok(state, layout) => { Self::Ok(state, layout) => state.get_content(layout),
state.get_content(layout)
},
Self::Err(_error) => { Self::Err(_error) => {
Box::new(())//&format!("EdnView error: {error:?}")) // FIXME: String is not Render panic!("{self:?}");
//TODO:&format!("EdnView error: {error:?}")) // FIXME: String is not Render
}, },
_ => todo!() _ => todo!()
} }

View file

@ -1,15 +1,38 @@
use crate::*; use crate::*;
/// Show one item if a condition is true and another if the condition is false /// Show one item if a condition is true and another if the condition is false
pub struct Either<A, B>(pub bool, pub A, pub B); pub struct Either<E, A, B>(pub PhantomData<E>, pub bool, pub A, pub B);
impl<E, A, B> Either<E, A, B> {
impl<E: Output, A: Render<E>, B: Render<E>> Content<E> for Either<A, B> { pub fn new (c: bool, a: A, b: B) -> Self {
Self(Default::default(), c, a, b)
}
}
impl<'a, T, E, A, B> TryFromEdn<'a, T> for Either<E, A, B>
where
T: EdnProvide<'a, bool> + EdnProvide<'a, B> + EdnProvide<'a, A> + 'a,
E: Output,
A: Render<E> + 'a,
B: Render<E> + 'a,
{
fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
use EdnItem::*;
if let (Key("either"), [condition, content, alternative]) = (head, tail) {
Some(Self::new(
state.get(condition).expect("either: no condition"),
state.get(content).expect("either: no content"),
state.get(alternative).expect("either: no alternative")
))
} else {
None
}
}
}
impl<E: Output, A: Render<E>, B: Render<E>> Content<E> for Either<E, A, B> {
fn layout (&self, to: E::Area) -> E::Area { fn layout (&self, to: E::Area) -> E::Area {
let Self(cond, a, b) = self; let Self(_, cond, a, b) = self;
if *cond { a.layout(to) } else { b.layout(to) } if *cond { a.layout(to) } else { b.layout(to) }
} }
fn render (&self, to: &mut E) { fn render (&self, to: &mut E) {
let Self(cond, a, b) = self; let Self(_, cond, a, b) = self;
if *cond { a.render(to) } else { b.render(to) } if *cond { a.render(to) } else { b.render(to) }
} }
} }

View file

@ -1,11 +1,35 @@
use crate::*; use crate::*;
/// Show an item only when a condition is true. /// Show an item only when a condition is true.
pub struct When<A>(pub bool, pub A); pub struct When<E, A>(pub PhantomData<E>, pub bool, pub A);
impl<E, A> When<E, A> {
impl<E: Output, A: Render<E>> Content<E> for When<A> { pub fn new (c: bool, a: A) -> Self {
Self(Default::default(), c, a)
}
}
impl<'a, T, E, A> TryFromEdn<'a, T> for When<E, A>
where
T: EdnProvide<'a, bool> + EdnProvide<'a, A> + 'a,
E: Output,
A: Render<E> + 'a
{
fn try_from_edn (
state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]
) -> Option<Self> {
use EdnItem::*;
if let (Key("when"), [condition, content]) = (head, tail) {
Some(Self(
Default::default(),
state.get(condition).expect("when: no condition"),
state.get(content).expect("when: no content")
))
} else {
None
}
}
}
impl<E: Output, A: Render<E>> Content<E> for When<E, A> {
fn layout (&self, to: E::Area) -> E::Area { fn layout (&self, to: E::Area) -> E::Area {
let Self(cond, item) = self; let Self(_, cond, item) = self;
let mut area = E::Area::zero(); let mut area = E::Area::zero();
if *cond { if *cond {
let item_area = item.layout(to); let item_area = item.layout(to);
@ -17,7 +41,7 @@ impl<E: Output, A: Render<E>> Content<E> for When<A> {
area.into() area.into()
} }
fn render (&self, to: &mut E) { fn render (&self, to: &mut E) {
let Self(cond, item) = self; let Self(_, cond, item) = self;
if *cond { item.render(to) } if *cond { item.render(to) }
} }
} }

View file

@ -1,3 +1 @@
(bsp/s (fill/x (fixed/y (align/x :toolbar))) (fill/x :toolbar)
(fill/x (align/c (bsp/w (align/e fixed/x :sidebar-w :pool))
(bsp/n :outputs (bsp/n :inputs (bsp/n :tracks :scenes)))))))

View file

@ -28,7 +28,7 @@ pub use ::tek_plugin::{self, *};
pub(crate) use std::error::Error; pub(crate) use std::error::Error;
pub(crate) use std::sync::atomic::{AtomicBool, Ordering::{self, *}}; pub(crate) use std::sync::atomic::{AtomicBool, Ordering::{self, *}};
pub(crate) use std::sync::{Arc, RwLock}; pub(crate) use std::sync::{Arc, RwLock};
#[derive(Default)] pub struct App { #[derive(Default, Debug)] pub struct App {
pub jack: Arc<RwLock<JackConnection>>, pub jack: Arc<RwLock<JackConnection>>,
pub edn: String, pub edn: String,
pub clock: Clock, pub clock: Clock,
@ -202,9 +202,6 @@ has_clock!(|self: Track|self.player.clock());
has_player!(|self: Track|self.player); has_player!(|self: Track|self.player);
impl Track { impl Track {
const MIN_WIDTH: usize = 9; const MIN_WIDTH: usize = 9;
fn longest_name (tracks: &[Self]) -> usize {
tracks.iter().map(|s|s.name.len()).fold(0, usize::max)
}
fn width_inc (&mut self) { fn width_inc (&mut self) {
self.width += 1; self.width += 1;
} }
@ -225,6 +222,9 @@ pub trait HasTracks: HasSelection + HasClock + HasJack + HasEditor + Send + Sync
fn midi_outs (&self) -> &Vec<JackPort<MidiOut>>; fn midi_outs (&self) -> &Vec<JackPort<MidiOut>>;
fn tracks (&self) -> &Vec<Track>; fn tracks (&self) -> &Vec<Track>;
fn tracks_mut (&mut self) -> &mut Vec<Track>; fn tracks_mut (&mut self) -> &mut Vec<Track>;
fn track_longest (&self) -> usize {
self.tracks().iter().map(|s|s.name.len()).fold(0, usize::max)
}
fn tracks_sizes <'a> (&'a self, editing: bool, bigger: usize) fn tracks_sizes <'a> (&'a self, editing: bool, bigger: usize)
-> impl Iterator<Item=(usize, &'a Track, usize, usize)> + Send + Sync + 'a -> impl Iterator<Item=(usize, &'a Track, usize, usize)> + Send + Sync + 'a
{ {
@ -341,9 +341,6 @@ impl Device for Plugin {}
color: ItemPalette, color: ItemPalette,
} }
impl Scene { impl Scene {
pub fn longest_name (scenes: &[Self]) -> usize {
scenes.iter().map(|s|s.name.len()).fold(0, usize::max)
}
/// Returns the pulse length of the longest clip in the scene /// Returns the pulse length of the longest clip in the scene
pub fn pulses (&self) -> usize { pub fn pulses (&self) -> usize {
self.clips.iter().fold(0, |a, p|{ self.clips.iter().fold(0, |a, p|{
@ -397,6 +394,9 @@ impl HasScenes for App {
pub trait HasScenes: HasSelection + HasEditor + Send + Sync { pub trait HasScenes: HasSelection + HasEditor + Send + Sync {
fn scenes (&self) -> &Vec<Scene>; fn scenes (&self) -> &Vec<Scene>;
fn scenes_mut (&mut self) -> &mut Vec<Scene>; fn scenes_mut (&mut self) -> &mut Vec<Scene>;
fn scene_longest (&self) -> usize {
self.scenes().iter().map(|s|s.name.len()).fold(0, usize::max)
}
fn scenes_sizes (&self, editing: bool, height: usize, larger: usize,) fn scenes_sizes (&self, editing: bool, height: usize, larger: usize,)
-> impl Iterator<Item = (usize, &Scene, usize, usize)> + Send + Sync -> impl Iterator<Item = (usize, &Scene, usize, usize)> + Send + Sync
{ {
@ -943,7 +943,7 @@ pub trait Arrangement: HasEditor + HasTracks + HasScenes + HasSelection + HasClo
bg.into(), bg.into(),
bg.into(), bg.into(),
)); ));
let cell = Either(active, editor, cell); let cell = Either::new(active, editor, cell);
*last_color.write().unwrap() = bg.into(); *last_color.write().unwrap() = bg.into();
map_south( map_south(
y1 as u16, y1 as u16,

View file

@ -39,11 +39,11 @@ render!(TuiOut: (self: ClockView<'a>) => Outer(
pub struct PlayPause { pub compact: bool, pub playing: bool } pub struct PlayPause { pub compact: bool, pub playing: bool }
render!(TuiOut: (self: PlayPause) => Tui::bg( render!(TuiOut: (self: PlayPause) => Tui::bg(
if self.playing{Color::Rgb(0,128,0)}else{Color::Rgb(128,64,0)}, if self.playing{Color::Rgb(0,128,0)}else{Color::Rgb(128,64,0)},
Either(self.compact, Either::new(self.compact,
Thunk::new(||Fixed::x(9, Either(self.playing, Thunk::new(||Fixed::x(9, Either::new(self.playing,
Tui::fg(Color::Rgb(0, 255, 0), " PLAYING "), Tui::fg(Color::Rgb(0, 255, 0), " PLAYING "),
Tui::fg(Color::Rgb(255, 128, 0), " STOPPED ")))), Tui::fg(Color::Rgb(255, 128, 0), " STOPPED ")))),
Thunk::new(||Fixed::x(5, Either(self.playing, Thunk::new(||Fixed::x(5, Either::new(self.playing,
Tui::fg(Color::Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)), Tui::fg(Color::Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
Tui::fg(Color::Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",)))))))); Tui::fg(Color::Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))))));
@ -63,7 +63,7 @@ impl BeatStats {
Self { compact, bpm, beat, time } Self { compact, bpm, beat, time }
} }
} }
render!(TuiOut: (self: BeatStats) => Either(self.compact, render!(TuiOut: (self: BeatStats) => Either::new(self.compact,
row!( row!(
FieldV(TuiTheme::g(128).into(), "BPM", &self.bpm), FieldV(TuiTheme::g(128).into(), "BPM", &self.bpm),
FieldV(TuiTheme::g(128).into(), "Beat", &self.beat), FieldV(TuiTheme::g(128).into(), "Beat", &self.beat),
@ -92,7 +92,7 @@ impl OutputStats {
} }
} }
} }
render!(TuiOut: (self: OutputStats) => Either(self.compact, render!(TuiOut: (self: OutputStats) => Either::new(self.compact,
row!( row!(
FieldV(TuiTheme::g(128).into(), "SR", &self.sample_rate), FieldV(TuiTheme::g(128).into(), "SR", &self.sample_rate),
FieldV(TuiTheme::g(128).into(), "Buf", &self.buffer_size), FieldV(TuiTheme::g(128).into(), "Buf", &self.buffer_size),

View file

@ -1,6 +1,7 @@
use crate::*; use crate::*;
/// Performance counter /// Performance counter
#[derive(Debug)]
pub struct PerfModel { pub struct PerfModel {
pub enabled: bool, pub enabled: bool,
clock: quanta::Clock, clock: quanta::Clock,

View file

@ -112,7 +112,7 @@ pub fn phat_sel_3 <T: Content<TuiOut>> (
selected: bool, field_1: T, field_2: T, top: Option<Color>, middle: Color, bottom: Color selected: bool, field_1: T, field_2: T, top: Option<Color>, middle: Color, bottom: Color
) -> impl Content<TuiOut> { ) -> impl Content<TuiOut> {
let border = Style::default().fg(Color::Rgb(255,255,255)).bg(middle); let border = Style::default().fg(Color::Rgb(255,255,255)).bg(middle);
Either(selected, Either::new(selected,
Tui::bg(middle, Outer(border).enclose(Align::w(Bsp::s("", Bsp::n("", Fill::y(field_1)))))), Tui::bg(middle, Outer(border).enclose(Align::w(Bsp::s("", Bsp::n("", Fill::y(field_1)))))),
Bsp::s(Fixed::y(1, top.map(|top|phat_lo(middle, top))), Bsp::s(Fixed::y(1, top.map(|top|phat_lo(middle, top))),
Bsp::n(Fixed::y(1, phat_hi(middle, bottom)), Bsp::n(Fixed::y(1, phat_hi(middle, bottom)),