mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
ok now it fails in a different place
This commit is contained in:
parent
585bba6666
commit
23fe9f0949
9 changed files with 82 additions and 130 deletions
|
|
@ -32,8 +32,8 @@ mod try_from_edn; pub use self::try_from_edn::*;
|
|||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_edn_layout () -> Result<(), ParseError> {
|
||||
EdnItem::<String>::read_all(include_str!("../../tek/examples/edn01.edn"))?;
|
||||
EdnItem::<String>::read_all(include_str!("../../tek/examples/edn02.edn"))?;
|
||||
EdnItem::<String>::read_all(include_str!("../../output/examples/edn01.edn"))?;
|
||||
EdnItem::<String>::read_all(include_str!("../../output/examples/edn02.edn"))?;
|
||||
//panic!("{layout:?}");
|
||||
//let content = <dyn EdnViewData<::tek_engine::tui::Tui>>::from(&layout);
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -45,26 +45,21 @@ impl<E: Output, A: Content<E>> Content<E> for Align<E, A> {
|
|||
to.place(Content::layout(self, to.area()), &self.content())
|
||||
}
|
||||
}
|
||||
impl<'a, T, E, A> TryFromEdn<'a, T> for Align<E, A>
|
||||
where
|
||||
T: EdnProvide<'a, A> + 'a,
|
||||
E: Output,
|
||||
A: Render<E> + 'a,
|
||||
{
|
||||
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Align<E, RenderBox<'a, E>> {
|
||||
fn try_from_edn (state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
|
||||
use EdnItem::*;
|
||||
Some(match (head, tail) {
|
||||
(Key("align/c"), [a]) => Self::c(state.get(a).expect("no content")),
|
||||
(Key("align/x"), [a]) => Self::x(state.get(a).expect("no content")),
|
||||
(Key("align/y"), [a]) => Self::y(state.get(a).expect("no content")),
|
||||
(Key("align/n"), [a]) => Self::n(state.get(a).expect("no content")),
|
||||
(Key("align/s"), [a]) => Self::s(state.get(a).expect("no content")),
|
||||
(Key("align/e"), [a]) => Self::e(state.get(a).expect("no content")),
|
||||
(Key("align/w"), [a]) => Self::w(state.get(a).expect("no content")),
|
||||
(Key("align/nw"), [a]) => Self::nw(state.get(a).expect("no content")),
|
||||
(Key("align/ne"), [a]) => Self::ne(state.get(a).expect("no content")),
|
||||
(Key("align/sw"), [a]) => Self::sw(state.get(a).expect("no content")),
|
||||
(Key("align/se"), [a]) => Self::se(state.get(a).expect("no content")),
|
||||
(Key("align/c"), [a]) => Self::c(state.get_content(a).expect("no content")),
|
||||
(Key("align/x"), [a]) => Self::x(state.get_content(a).expect("no content")),
|
||||
(Key("align/y"), [a]) => Self::y(state.get_content(a).expect("no content")),
|
||||
(Key("align/n"), [a]) => Self::n(state.get_content(a).expect("no content")),
|
||||
(Key("align/s"), [a]) => Self::s(state.get_content(a).expect("no content")),
|
||||
(Key("align/e"), [a]) => Self::e(state.get_content(a).expect("no content")),
|
||||
(Key("align/w"), [a]) => Self::w(state.get_content(a).expect("no content")),
|
||||
(Key("align/nw"), [a]) => Self::nw(state.get_content(a).expect("no content")),
|
||||
(Key("align/ne"), [a]) => Self::ne(state.get_content(a).expect("no content")),
|
||||
(Key("align/sw"), [a]) => Self::sw(state.get_content(a).expect("no content")),
|
||||
(Key("align/se"), [a]) => Self::se(state.get_content(a).expect("no content")),
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,22 +91,16 @@ impl<E: Output, A: Content<E>, B: Content<E>> BspAreas<E, A, B> for Bsp<E, A, B>
|
|||
fn direction (&self) -> Direction { self.1 }
|
||||
fn contents (&self) -> (&A, &B) { (&self.2, &self.3) }
|
||||
}
|
||||
impl<'a, T, E, A, B> TryFromEdn<'a, T> for Bsp<E, A, B>
|
||||
where
|
||||
T: EdnProvide<'a, A> + EdnProvide<'a, B> + 'a,
|
||||
E: Output,
|
||||
A: Render<E> + 'a,
|
||||
B: Render<E> + 'a,
|
||||
{
|
||||
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Bsp<E, RenderBox<'a, E>, RenderBox<'a, E>> {
|
||||
fn try_from_edn (s: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]) -> Option<Self> {
|
||||
use EdnItem::*;
|
||||
Some(match (head, tail) {
|
||||
(Key("bsp/n"), [a, b]) => Self::n(s.get(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/s"), [a, b]) => Self::s(s.get(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/e"), [a, b]) => Self::e(s.get(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/w"), [a, b]) => Self::w(s.get(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/a"), [a, b]) => Self::a(s.get(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/b"), [a, b]) => Self::b(s.get(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/n"), [a, b]) => Self::n(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/s"), [a, b]) => Self::s(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/e"), [a, b]) => Self::e(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/w"), [a, b]) => Self::w(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/a"), [a, b]) => Self::a(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||
(Key("bsp/b"), [a, b]) => Self::b(s.get_content(a).expect("no a"), s.get(b).expect("no b")),
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,77 +69,59 @@ pub trait EdnViewData<'a, E: Output>:
|
|||
EdnProvide<'a, E::Unit> +
|
||||
EdnProvide<'a, Box<dyn Render<E> + 'a>>
|
||||
{
|
||||
fn get_bool (&'a self, item: &'a EdnItem<&str>) -> bool {
|
||||
match &item {
|
||||
Num(0) => false,
|
||||
Num(_) => true,
|
||||
Sym(":true") | Sym(":t") => true,
|
||||
Sym(":false") | Sym(":f") => false,
|
||||
_ => EdnProvide::get_or_fail(self, item)
|
||||
fn get_bool (&'a self, item: &'a EdnItem<&str>) -> Option<bool> {
|
||||
Some(match &item {
|
||||
Sym(":false") | Sym(":f") | Num(0) => false,
|
||||
Sym(":true") | Sym(":t") | Num(_) => true,
|
||||
_ => return EdnProvide::get(self, item)
|
||||
})
|
||||
}
|
||||
fn get_usize (&'a self, item: &'a EdnItem<&str>) -> Option<usize> {
|
||||
Some(match &item { Num(n) => *n, _ => return EdnProvide::get(self, item) })
|
||||
}
|
||||
fn get_usize (&'a self, item: &'a EdnItem<&str>) -> usize {
|
||||
match &item { Num(n) => *n, _ => EdnProvide::get_or_fail(self, item) }
|
||||
fn get_unit (&'a self, item: &'a EdnItem<&str>) -> Option<E::Unit> {
|
||||
Some(match &item { Num(n) => (*n as u16).into(), _ => return EdnProvide::get(self, item) })
|
||||
}
|
||||
fn get_unit (&'a self, item: &'a EdnItem<&str>) -> E::Unit {
|
||||
match &item { Num(n) => (*n as u16).into(), _ => EdnProvide::get_or_fail(self, item) }
|
||||
}
|
||||
fn get_content (&'a self, item: &'a EdnItem<&'a str>) -> Box<dyn Render<E> + 'a> where E: 'a {
|
||||
match item {
|
||||
fn get_content (&'a self, item: &'a EdnItem<&'a str>) -> Option<Box<dyn Render<E> + 'a>> where E: 'a {
|
||||
Some(match item {
|
||||
Nil => Box::new(()),
|
||||
Exp(e) => if let [head, tail @ ..] = e.as_slice() {
|
||||
if let Some(builtin) = When::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Either::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(
|
||||
self, head, tail
|
||||
) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Align::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Bsp::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(
|
||||
self, head, tail
|
||||
) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Fill::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Fixed::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Min::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Max::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Shrink::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Expand::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Push::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Pull::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Margin::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
if let Some(builtin) = Padding::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
return builtin.boxed()
|
||||
}
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Either::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Align::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Bsp::<_, RenderBox<'a, E>, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Fill::<_, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Fixed::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Min::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Max::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Shrink::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Expand::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Push::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Pull::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Margin::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else if let Some(builtin) = Padding::<_, _, RenderBox<'a, E>>::try_from_edn(self, head, tail) {
|
||||
builtin.boxed()
|
||||
} else {
|
||||
EdnProvide::get_or_fail(self, &item)
|
||||
}
|
||||
} else {
|
||||
EdnProvide::get_or_fail(self, &item)
|
||||
},
|
||||
_ => EdnProvide::get_or_fail(self, &item)
|
||||
}
|
||||
})
|
||||
//panic!("no content")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,7 @@ impl<E, A, B> Either<E, A, B> {
|
|||
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,
|
||||
{
|
||||
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for Either<E, RenderBox<'a, E>, RenderBox<'a, E>> {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -27,20 +27,15 @@ macro_rules! transform_xy {
|
|||
$area
|
||||
}
|
||||
}
|
||||
impl<'a, T, E, A> TryFromEdn<'a, T> for $Enum<E, A>
|
||||
where
|
||||
T: EdnProvide<'a, A> + 'a,
|
||||
E: Output,
|
||||
A: Render<E> + 'a
|
||||
{
|
||||
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for $Enum<E, RenderBox<'a, E>> {
|
||||
fn try_from_edn (
|
||||
state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]
|
||||
) -> Option<Self> {
|
||||
use EdnItem::*;
|
||||
Some(match (head, tail) {
|
||||
(Key($x), [a]) => Self::x(state.get(a).expect("no content")),
|
||||
(Key($y), [a]) => Self::y(state.get(a).expect("no content")),
|
||||
(Key($xy), [a]) => Self::xy(state.get(a).expect("no content")),
|
||||
(Key($x), [a]) => Self::x(state.get_content(a).expect("no content")),
|
||||
(Key($y), [a]) => Self::y(state.get_content(a).expect("no content")),
|
||||
(Key($xy), [a]) => Self::xy(state.get_content(a).expect("no content")),
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,29 +41,24 @@ macro_rules! transform_xy_unit {
|
|||
$layout.into()
|
||||
}
|
||||
}
|
||||
impl<'a, T, E, A> TryFromEdn<'a, T> for $Enum<E, E::Unit, A>
|
||||
where
|
||||
T: EdnProvide<'a, E::Unit> + EdnProvide<'a, A> + 'a,
|
||||
E: Output,
|
||||
A: Render<E> + 'a,
|
||||
{
|
||||
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for $Enum<E, E::Unit, RenderBox<'a, E>> {
|
||||
fn try_from_edn (
|
||||
state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]
|
||||
) -> Option<Self> {
|
||||
use EdnItem::*;
|
||||
Some(match (head, tail) {
|
||||
(Key($x), [x, a]) => Self::x(
|
||||
state.get(x).expect("no content"),
|
||||
state.get(a).expect("no content"),
|
||||
state.get_unit(x).expect("no x"),
|
||||
state.get_content(a).expect("no content"),
|
||||
),
|
||||
(Key($y), [y, a]) => Self::y(
|
||||
state.get(y).expect("no content"),
|
||||
state.get(a).expect("no content"),
|
||||
state.get_unit(y).expect("no y"),
|
||||
state.get_content(a).expect("no content"),
|
||||
),
|
||||
(Key($xy), [x, y, a]) => Self::xy(
|
||||
state.get(x).expect("no content"),
|
||||
state.get(y).expect("no content"),
|
||||
state.get(a).expect("no content"),
|
||||
state.get_unit(x).expect("no x"),
|
||||
state.get_unit(y).expect("no y"),
|
||||
state.get_content(a).expect("no content"),
|
||||
),
|
||||
_ => return None
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,12 +6,7 @@ impl<E, A> When<E, A> {
|
|||
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
|
||||
{
|
||||
impl<'a, E: Output + 'a, T: EdnViewData<'a, E>> TryFromEdn<'a, T> for When<E, RenderBox<'a, E>> {
|
||||
fn try_from_edn (
|
||||
state: &'a T, head: &EdnItem<&str>, tail: &'a [EdnItem<&str>]
|
||||
) -> Option<Self> {
|
||||
|
|
@ -19,8 +14,8 @@ where
|
|||
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")
|
||||
state.get_bool(condition).expect("when: no condition"),
|
||||
state.get_content(content).expect("when: no content")
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
(fill/x (fixed/y 2 :toolbar))
|
||||
(bsp/s :toolbar
|
||||
(fill/x (align/c (bsp/w :pool
|
||||
(bsp/n :outputs (bsp/n :inputs (bsp/n :tracks :scenes)))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue