mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
extract match_exp
This commit is contained in:
parent
9a70fbc416
commit
3975837393
3 changed files with 56 additions and 48 deletions
|
|
@ -50,7 +50,7 @@ impl EdnItem<&str> {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl<T: AsRef<str> + PartialEq + Default + Clone + std::fmt::Debug> EdnItem<T> {
|
||||
impl<T: AsRef<str>> EdnItem<T> {
|
||||
pub fn to_ref (&self) -> EdnItem<&str> {
|
||||
match self {
|
||||
Self::Nil => EdnItem::Nil,
|
||||
|
|
|
|||
|
|
@ -46,48 +46,10 @@ impl<E: Output, T: EdnViewData<E> + Send + Sync> Content<E> for EdnView<E, T> {
|
|||
Key(t) => panic!("todo: add error handling to content() chain. unexpected key {t}"),
|
||||
Num(n) => panic!("todo: add error handling to content() chain. unexpected num {n}"),
|
||||
Exp(e) => if let [head, tail @ ..] = e.as_slice() {
|
||||
let head = &head.to_ref();
|
||||
match (head, tail) {
|
||||
|
||||
(Key("align/c"), [a]) => Align::c(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/x"), [a]) => Align::x(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/y"), [a]) => Align::y(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/n"), [a]) => Align::n(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/s"), [a]) => Align::s(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/e"), [a]) => Align::e(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/w"), [a]) => Align::w(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/nw"), [a]) => Align::nw(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/ne"), [a]) => Align::ne(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/sw"), [a]) => Align::sw(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/se"), [a]) => Align::se(s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("bsp/a"), [a, b]) => Bsp::a(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/b"), [a, b]) => Bsp::b(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/e"), [a, b]) => Bsp::e(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/n"), [a, b]) => Bsp::n(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/s"), [a, b]) => Bsp::s(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/w"), [a, b]) => Bsp::w(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
|
||||
(Key("fill/x"), [a]) => Fill::x(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fill/y"), [a]) => Fill::y(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fill/xy"), [a]) => Fill::xy(s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("fixed/x"), [x, a]) => Fixed::x(s.get_unit(x.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fixed/y"), [y, a]) => Fixed::y(s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fixed/xy"), [x, y, a]) => Fixed::xy(s.get_unit(x.to_ref()), s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("max/x"), [x, a]) => Max::x(s.get_unit(x.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("max/y"), [y, a]) => Max::y(s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("push/x"), [x, a]) => Push::x(s.get_unit(x.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("push/y"), [y, a]) => Push::y(s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("when"), [c, a]) => When(s.get_bool(c.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
_ => todo!("{:?} {:?}", &head, &tail)
|
||||
}
|
||||
match_exp(s, &head.to_ref(), &tail)
|
||||
} else {
|
||||
panic!("todo: add error handling to content() chain. invalid expression {e:?}")
|
||||
panic!("todo: add error handling to content() chain. invalid expression {e:?}");
|
||||
().boxed()
|
||||
},
|
||||
},
|
||||
Self::Err(error) => {
|
||||
|
|
@ -99,3 +61,48 @@ impl<E: Output, T: EdnViewData<E> + Send + Sync> Content<E> for EdnView<E, T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn match_exp <'a, E: Output + 'a, State: EdnViewData<E>> (
|
||||
s: &'a State,
|
||||
head: &EdnItem<&str>,
|
||||
tail: &'a [EdnItem<String>]
|
||||
) -> Box<dyn Render<E> + 'a> {
|
||||
match (head, tail) {
|
||||
|
||||
(Key("align/c"), [a]) => Align::c(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/x"), [a]) => Align::x(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/y"), [a]) => Align::y(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/n"), [a]) => Align::n(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/s"), [a]) => Align::s(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/e"), [a]) => Align::e(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/w"), [a]) => Align::w(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/nw"), [a]) => Align::nw(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/ne"), [a]) => Align::ne(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/sw"), [a]) => Align::sw(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("align/se"), [a]) => Align::se(s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("bsp/a"), [a, b]) => Bsp::a(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/b"), [a, b]) => Bsp::b(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/e"), [a, b]) => Bsp::e(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/n"), [a, b]) => Bsp::n(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/s"), [a, b]) => Bsp::s(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
(Key("bsp/w"), [a, b]) => Bsp::w(s.get_content(a.to_ref()), s.get_content(b.to_ref()),).boxed(),
|
||||
|
||||
(Key("fill/x"), [a]) => Fill::x(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fill/y"), [a]) => Fill::y(s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fill/xy"), [a]) => Fill::xy(s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("fixed/x"), [x, a]) => Fixed::x(s.get_unit(x.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fixed/y"), [y, a]) => Fixed::y(s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("fixed/xy"), [x, y, a]) => Fixed::xy(s.get_unit(x.to_ref()), s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("max/x"), [x, a]) => Max::x(s.get_unit(x.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("max/y"), [y, a]) => Max::y(s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("push/x"), [x, a]) => Push::x(s.get_unit(x.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
(Key("push/y"), [y, a]) => Push::y(s.get_unit(y.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
(Key("when"), [c, a]) => When(s.get_bool(c.to_ref()), s.get_content(a.to_ref())).boxed(),
|
||||
|
||||
_ => todo!("{:?} {:?}", &head, &tail)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,6 @@ use EdnItem::*;
|
|||
|
||||
const EDN: &'static str = include_str!("groovebox.edn");
|
||||
|
||||
//impl Content<TuiOut> for Groovebox {
|
||||
//fn content (&self) -> impl Render<TuiOut> {
|
||||
//self.size.of(EdnView::from_source(self, EDN))
|
||||
//}
|
||||
//}
|
||||
|
||||
// this works:
|
||||
render!(TuiOut: (self: Groovebox) => self.size.of(
|
||||
Bsp::s(self.toolbar_view(),
|
||||
|
|
@ -19,6 +13,13 @@ render!(TuiOut: (self: Groovebox) => self.size.of(
|
|||
Bsp::n(self.status_view(),
|
||||
Bsp::w(self.pool_view(), Fill::xy(Bsp::e(self.sampler_view(), &self.editor)))))))));
|
||||
|
||||
// this almost works:
|
||||
//impl Content<TuiOut> for Groovebox {
|
||||
//fn content (&self) -> impl Render<TuiOut> {
|
||||
//self.size.of(EdnView::from_source(self, EDN))
|
||||
//}
|
||||
//}
|
||||
|
||||
impl Groovebox {
|
||||
fn toolbar_view (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
Fill::x(Fixed::y(2, lay!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue