mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 18:49:04 +01:00
wip: refactor(output): pen and paper ftw
This commit is contained in:
parent
501782f8fe
commit
eaa05b7f09
26 changed files with 1701 additions and 1697 deletions
351
output/.scratch.rs
Normal file
351
output/.scratch.rs
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///// The syntagm `(when :condition :content)` corresponds to a [When] layout element.
|
||||
//impl<S, A> FromDsl<S> for When<A> where bool: FromDsl<S>, A: FromDsl<S> {
|
||||
//fn try_provide (state: &S, source: &DslVal<impl DslStr, impl DslExpr>) -> Perhaps<Self> {
|
||||
//source.exp_match("when", |_, tail|Ok(Some(Self(
|
||||
//FromDsl::<S>::provide(state,
|
||||
//tail.nth(0, ||"no condition".into())?, ||"no condition".into())?,
|
||||
//FromDsl::<S>::provide(state,
|
||||
//tail.nth(1, ||"no content".into())?, ||"no content".into())?,
|
||||
//))))
|
||||
//}
|
||||
//}
|
||||
///// The syntagm `(either :condition :content1 :content2)` corresponds to an [Either] layout element.
|
||||
//impl<S, A, B> FromDsl<S> for Either<A, B> where S: Eval<Ast, bool> + Eval<Ast, A> + Eval<Ast, B> {
|
||||
//fn try_provide (state: &S, source: &DslVal<impl DslStr, impl DslExpr>) -> Perhaps<Self> {
|
||||
//source.exp_match("either", |_, tail|Ok(Some(Self(
|
||||
//state.eval(tail.nth(0, ||"no condition")?, ||"no condition")?,
|
||||
//state.eval(tail.nth(1, ||"no content 1")?, ||"no content 1")?,
|
||||
//state.eval(tail.nth(2, ||"no content 1")?, ||"no content 2")?,
|
||||
//))))
|
||||
//}
|
||||
//}
|
||||
///// The syntagm `(align/* :content)` corresponds to an [Align] layout element,
|
||||
///// where `*` specifies the direction of the alignment.
|
||||
//impl<S, A> FromDsl<S> for Align<A> where S: Eval<Option<Ast>, A> {
|
||||
//fn try_provide (state: &S, source: &DslVal<impl DslStr, impl DslExpr>) -> Perhaps<Self> {
|
||||
//source.exp_match("align/", |head, tail|Ok(Some(match head {
|
||||
//"c" => Self::c(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"x" => Self::x(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"y" => Self::y(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"n" => Self::n(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"s" => Self::s(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"e" => Self::e(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"w" => Self::w(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"nw" => Self::nw(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"ne" => Self::ne(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"sw" => Self::sw(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//"se" => Self::se(state.eval(tail.nth(0, ||"no content")?, ||"no content")),
|
||||
//_ => return Err("invalid align variant".into())
|
||||
//})))
|
||||
//}
|
||||
//}
|
||||
///// The syntagm `(bsp/* :content1 :content2)` corresponds to a [Bsp] layout element,
|
||||
///// where `*` specifies the direction of the split.
|
||||
//impl<S, A, B> FromDsl<S> for Bsp<A, B> where S: Eval<Option<Ast>, A> + Eval<Option<Ast>, B> {
|
||||
//fn try_provide (state: &S, source: &DslVal<impl DslStr, impl DslExpr>) -> Perhaps<Self> {
|
||||
//source.exp_match("bsp/", |head, tail|Ok(Some(match head {
|
||||
//"n" => Self::n(tail.nth(0, ||"no content 1"), tail.nth(1, ||"no content 2")),
|
||||
//"s" => Self::s(tail.nth(0, ||"no content 1"), tail.nth(1, ||"no content 2")),
|
||||
//"e" => Self::e(tail.nth(0, ||"no content 1"), tail.nth(1, ||"no content 2")),
|
||||
//"w" => Self::w(tail.nth(0, ||"no content 1"), tail.nth(1, ||"no content 2")),
|
||||
//"a" => Self::a(tail.nth(0, ||"no content 1"), tail.nth(1, ||"no content 2")),
|
||||
//"b" => Self::b(tail.nth(0, ||"no content 1"), tail.nth(1, ||"no content 2")),
|
||||
//_ => return Ok(None),
|
||||
//})))
|
||||
//}
|
||||
//}
|
||||
//#[cfg(feature = "dsl")] take!($Enum<A>, A|state, words|Ok(
|
||||
//if let Some(Token { value: Key(k), .. }) = words.peek() {
|
||||
//let mut base = words.clone();
|
||||
//let content = state.give_or_fail(words, ||format!("{k}: no content"))?;
|
||||
//return Ok(Some(match words.next() {
|
||||
//Some(Token{value: Key($x),..}) => Self::x(content),
|
||||
//Some(Token{value: Key($y),..}) => Self::y(content),
|
||||
//Some(Token{value: Key($xy),..}) => Self::XY(content),
|
||||
//_ => unreachable!()
|
||||
//}))
|
||||
//} else {
|
||||
//None
|
||||
//}));
|
||||
//#[cfg(feature = "dsl")] take!($Enum<U, A>, U, A|state, words|Ok(
|
||||
//if let Some(Token { value: Key($x|$y|$xy), .. }) = words.peek() {
|
||||
//let mut base = words.clone();
|
||||
//Some(match words.next() {
|
||||
//Some(Token { value: Key($x), .. }) => Self::x(
|
||||
//state.give_or_fail(words, ||"x: no unit")?,
|
||||
//state.give_or_fail(words, ||"x: no content")?,
|
||||
//),
|
||||
//Some(Token { value: Key($y), .. }) => Self::y(
|
||||
//state.give_or_fail(words, ||"y: no unit")?,
|
||||
//state.give_or_fail(words, ||"y: no content")?,
|
||||
//),
|
||||
//Some(Token { value: Key($x), .. }) => Self::XY(
|
||||
//state.give_or_fail(words, ||"xy: no unit x")?,
|
||||
//state.give_or_fail(words, ||"xy: no unit y")?,
|
||||
//state.give_or_fail(words, ||"xy: no content")?
|
||||
//),
|
||||
//_ => unreachable!(),
|
||||
//})
|
||||
//} else {
|
||||
//None
|
||||
//}));
|
||||
//if let Exp(_, exp) = source.value() {
|
||||
//let mut rest = exp.clone();
|
||||
//return Ok(Some(match rest.next().as_ref().and_then(|x|x.key()) {
|
||||
//Some("bsp/n") => Self::n(
|
||||
//state.eval(rest.next(), ||"bsp/n: no content 1")?,
|
||||
//state.eval(rest.next(), ||"bsp/n: no content 2")?,
|
||||
//),
|
||||
//Some("bsp/s") => Self::s(
|
||||
//state.eval(rest.next(), ||"bsp/s: no content 1")?,
|
||||
//state.eval(rest.next(), ||"bsp/s: no content 2")?,
|
||||
//),
|
||||
//Some("bsp/e") => Self::e(
|
||||
//state.eval(rest.next(), ||"bsp/e: no content 1")?,
|
||||
//state.eval(rest.next(), ||"bsp/e: no content 2")?,
|
||||
//),
|
||||
//Some("bsp/w") => Self::w(
|
||||
//state.eval(rest.next(), ||"bsp/w: no content 1")?,
|
||||
//state.eval(rest.next(), ||"bsp/w: no content 2")?,
|
||||
//),
|
||||
//Some("bsp/a") => Self::a(
|
||||
//state.eval(rest.next(), ||"bsp/a: no content 1")?,
|
||||
//state.eval(rest.next(), ||"bsp/a: no content 2")?,
|
||||
//),
|
||||
//Some("bsp/b") => Self::b(
|
||||
//state.eval(rest.next(), ||"bsp/b: no content 1")?,
|
||||
//state.eval(rest.next(), ||"bsp/b: no content 2")?,
|
||||
//),
|
||||
//_ => return Ok(None),
|
||||
//}))
|
||||
//}
|
||||
//Ok(None)
|
||||
//if let Exp(_, source) = source.value() {
|
||||
//let mut rest = source.clone();
|
||||
//return Ok(Some(match rest.next().as_ref().and_then(|x|x.key()) {
|
||||
//Some("align/c") => Self::c(state.eval(rest.next(), ||"align/c: no content")?),
|
||||
//Some("align/x") => Self::x(state.eval(rest.next(), ||"align/x: no content")?),
|
||||
//Some("align/y") => Self::y(state.eval(rest.next(), ||"align/y: no content")?),
|
||||
//Some("align/n") => Self::n(state.eval(rest.next(), ||"align/n: no content")?),
|
||||
//Some("align/s") => Self::s(state.eval(rest.next(), ||"align/s: no content")?),
|
||||
//Some("align/e") => Self::e(state.eval(rest.next(), ||"align/e: no content")?),
|
||||
//Some("align/w") => Self::w(state.eval(rest.next(), ||"align/w: no content")?),
|
||||
//Some("align/nw") => Self::nw(state.eval(rest.next(), ||"align/nw: no content")?),
|
||||
//Some("align/ne") => Self::ne(state.eval(rest.next(), ||"align/ne: no content")?),
|
||||
//Some("align/sw") => Self::sw(state.eval(rest.next(), ||"align/sw: no content")?),
|
||||
//Some("align/se") => Self::se(state.eval(rest.next(), ||"align/se: no content")?),
|
||||
//_ => return Ok(None),
|
||||
//}))
|
||||
//}
|
||||
//Ok(None)
|
||||
//Ok(match source.exp_head().and_then(|e|e.key()) {
|
||||
//Some("either") => Some(Self(
|
||||
//source.exp_tail().and_then(|t|t.get(0)).map(|x|state.eval(x, ||"when: no condition"))?,
|
||||
//source.exp_tail().and_then(|t|t.get(1)).map(|x|state.eval(x, ||"when: no content 1"))?,
|
||||
//source.exp_tail().and_then(|t|t.get(2)).map(|x|state.eval(x, ||"when: no content 2"))?,
|
||||
//)),
|
||||
//_ => None
|
||||
//})
|
||||
//if let Exp(_, mut exp) = source.value()
|
||||
//&& let Some(Ast(Key(id))) = exp.peek() && *id == *"either" {
|
||||
//let _ = exp.next();
|
||||
//return Ok(Some(Self(
|
||||
//state.eval(exp.next().unwrap(), ||"either: no condition")?,
|
||||
//state.eval(exp.next().unwrap(), ||"either: no content 1")?,
|
||||
//state.eval(exp.next().unwrap(), ||"either: no content 2")?,
|
||||
//)))
|
||||
//}
|
||||
//Ok(None)
|
||||
//Ok(match source.exp_head().and_then(|e|e.key()) {
|
||||
//Some("when") => Some(Self(
|
||||
//source.exp_tail().and_then(|t|t.get(0)).map(|x|state.eval(x, ||"when: no condition"))?,
|
||||
//source.exp_tail().and_then(|t|t.get(1)).map(|x|state.eval(x, ||"when: no content"))?,
|
||||
//)),
|
||||
//_ => None
|
||||
//})
|
||||
//use crate::*;
|
||||
//use Direction::*;
|
||||
|
||||
//pub struct Stack<'x, E, F1> {
|
||||
//__: PhantomData<&'x (E, F1)>,
|
||||
//direction: Direction,
|
||||
//callback: F1
|
||||
//}
|
||||
|
||||
//impl<'x, E, F1> Stack<'x, E, F1> {
|
||||
//pub fn new (direction: Direction, callback: F1) -> Self {
|
||||
//Self { direction, callback, __: Default::default(), }
|
||||
//}
|
||||
//pub fn above (callback: F1) -> Self {
|
||||
//Self::new(Above, callback)
|
||||
//}
|
||||
//pub fn below (callback: F1) -> Self {
|
||||
//Self::new(Below, callback)
|
||||
//}
|
||||
//pub fn north (callback: F1) -> Self {
|
||||
//Self::new(North, callback)
|
||||
//}
|
||||
//pub fn south (callback: F1) -> Self {
|
||||
//Self::new(South, callback)
|
||||
//}
|
||||
//pub fn east (callback: F1) -> Self {
|
||||
//Self::new(East, callback)
|
||||
//}
|
||||
//pub fn west (callback: F1) -> Self {
|
||||
//Self::new(West, callback)
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl<'x, E: Out, F1: Fn(&mut dyn FnMut(&dyn Layout<E>))> Layout<E> for Stack<'x, E, F1> {
|
||||
//fn layout (&self, to: E::Area) -> E::Area {
|
||||
//let state = StackLayoutState::<E>::new(self.direction, to);
|
||||
//(self.callback)(&mut |component: &dyn Layout<E>|{
|
||||
//let StackLayoutState { x, y, w_remaining, h_remaining, .. } = *state.borrow();
|
||||
//let [_, _, w, h] = component.layout([x, y, w_remaining, h_remaining].into()).xywh();
|
||||
//state.borrow_mut().grow(w, h);
|
||||
//});
|
||||
//let StackLayoutState { w_used, h_used, .. } = *state.borrow();
|
||||
//match self.direction {
|
||||
//North | West => { todo!() },
|
||||
//South | East => { [to.x(), to.y(), w_used, h_used].into() },
|
||||
//_ => unreachable!(),
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//impl<'x, E: Out, F1: Fn(&mut dyn FnMut(&dyn Draw<E>))> Draw<E> for Stack<'x, E, F1> {
|
||||
//fn draw (&self, to: &mut E) {
|
||||
//let state = StackLayoutState::<E>::new(self.direction, to.area());
|
||||
//let to = Rc::new(RefCell::new(to));
|
||||
//(self.callback)(&mut |component: &dyn Draw<E>|{
|
||||
//let StackLayoutState { x, y, w_remaining, h_remaining, .. } = *state.borrow();
|
||||
//let layout = component.layout([x, y, w_remaining, h_remaining].into());
|
||||
//state.borrow_mut().grow(layout.w(), layout.h());
|
||||
//to.borrow_mut().place_at(layout, component);
|
||||
//});
|
||||
//}
|
||||
//}
|
||||
|
||||
//#[derive(Copy, Clone)]
|
||||
//struct StackLayoutState<E: Out> {
|
||||
//direction: Direction,
|
||||
//x: E::Unit,
|
||||
//y: E::Unit,
|
||||
//w_used: E::Unit,
|
||||
//h_used: E::Unit,
|
||||
//w_remaining: E::Unit,
|
||||
//h_remaining: E::Unit,
|
||||
//}
|
||||
//impl<E: Out> StackLayoutState<E> {
|
||||
//fn new (direction: Direction, area: E::Area) -> std::rc::Rc<std::cell::RefCell<Self>> {
|
||||
//let [x, y, w_remaining, h_remaining] = area.xywh();
|
||||
//std::rc::Rc::new(std::cell::RefCell::new(Self {
|
||||
//direction,
|
||||
//x, y, w_remaining, h_remaining,
|
||||
//w_used: E::Unit::zero(), h_used: E::Unit::zero()
|
||||
//}))
|
||||
//}
|
||||
//fn grow (&mut self, w: E::Unit, h: E::Unit) -> &mut Self {
|
||||
//match self.direction {
|
||||
//South => { self.y = self.y.plus(h);
|
||||
//self.h_used = self.h_used.plus(h);
|
||||
//self.h_remaining = self.h_remaining.minus(h);
|
||||
//self.w_used = self.w_used.max(w); },
|
||||
//East => { self.x = self.x.plus(w);
|
||||
//self.w_used = self.w_used.plus(w);
|
||||
//self.w_remaining = self.w_remaining.minus(w);
|
||||
//self.h_used = self.h_used.max(h); },
|
||||
//North | West => { todo!() },
|
||||
//Above | Below => {},
|
||||
//};
|
||||
//self
|
||||
//}
|
||||
//fn area_remaining (&self) -> E::Area {
|
||||
//[self.x, self.y, self.w_remaining, self.h_remaining].into()
|
||||
//}
|
||||
//}
|
||||
|
||||
////pub struct Stack<'a, E, F1> {
|
||||
////__: PhantomData<&'a (E, F1)>,
|
||||
////direction: Direction,
|
||||
////callback: F1
|
||||
////}
|
||||
////impl<'a, E, F1> Stack<'a, E, F1> where
|
||||
////E: Out, F1: Fn(&mut dyn FnMut(&'a dyn Draw<E>)) + Send + Sync,
|
||||
////{
|
||||
////pub fn north (callback: F1) -> Self { Self::new(North, callback) }
|
||||
////pub fn south (callback: F1) -> Self { Self::new(South, callback) }
|
||||
////pub fn east (callback: F1) -> Self { Self::new(East, callback) }
|
||||
////pub fn west (callback: F1) -> Self { Self::new(West, callback) }
|
||||
////pub fn above (callback: F1) -> Self { Self::new(Above, callback) }
|
||||
////pub fn below (callback: F1) -> Self { Self::new(Below, callback) }
|
||||
////pub fn new (direction: Direction, callback: F1) -> Self {
|
||||
////Self { direction, callback, __: Default::default(), }
|
||||
////}
|
||||
////}
|
||||
////impl<'a, E, F1> Draw<E> for Stack<'a, E, F1> where
|
||||
////E: Out, F1: Fn(&mut dyn FnMut(&'a dyn Draw<E>)) + Send + Sync,
|
||||
////{
|
||||
////fn layout (&self, to: E::Area) -> E::Area {
|
||||
////let state = StackLayoutState::<E>::new(self.direction, to);
|
||||
////let mut adder = {
|
||||
////let state = state.clone();
|
||||
////move|component: &dyn Draw<E>|{
|
||||
////let [w, h] = component.layout(state.borrow().area_remaining()).wh();
|
||||
////state.borrow_mut().grow(w, h);
|
||||
////}
|
||||
////};
|
||||
////(self.callback)(&mut adder);
|
||||
////let StackLayoutState { w_used, h_used, .. } = *state.borrow();
|
||||
////match self.direction {
|
||||
////North | West => { todo!() },
|
||||
////South | East => { [to.x(), to.y(), w_used, h_used].into() },
|
||||
////Above | Below => { [to.x(), to.y(), to.w(), to.h()].into() },
|
||||
////}
|
||||
////}
|
||||
////fn draw (&self, to: &mut E) {
|
||||
////let state = StackLayoutState::<E>::new(self.direction, to.area());
|
||||
////let mut adder = {
|
||||
////let state = state.clone();
|
||||
////move|component: &dyn Draw<E>|{
|
||||
////let [x, y, w, h] = component.layout(state.borrow().area_remaining()).xywh();
|
||||
////state.borrow_mut().grow(w, h);
|
||||
////to.place_at([x, y, w, h].into(), component);
|
||||
////}
|
||||
////};
|
||||
////(self.callback)(&mut adder);
|
||||
////}
|
||||
////}
|
||||
|
||||
//[>Stack::down(|add|{
|
||||
//let mut i = 0;
|
||||
//for (_, name) in self.dirs.iter() {
|
||||
//if i >= self.scroll {
|
||||
//add(&Tui::bold(i == self.index, name.as_str()))?;
|
||||
//}
|
||||
//i += 1;
|
||||
//}
|
||||
//for (_, name) in self.files.iter() {
|
||||
//if i >= self.scroll {
|
||||
//add(&Tui::bold(i == self.index, name.as_str()))?;
|
||||
//}
|
||||
//i += 1;
|
||||
//}
|
||||
//add(&format!("{}/{i}", self.index))?;
|
||||
//Ok(())
|
||||
//}));*/
|
||||
|
||||
|
||||
//#[test] fn test_iter_map () {
|
||||
//struct Foo;
|
||||
//impl<T: Out> Content<T> for Foo {}
|
||||
//fn _make_map <T: Out, U: Content<T> + Send + Sync> (data: &Vec<U>) -> impl Draw<T> {
|
||||
//Map::new(||data.iter(), |_foo, _index|{})
|
||||
//}
|
||||
//let _data = vec![Foo, Foo, Foo];
|
||||
////let map = make_map(&data);
|
||||
//}
|
||||
Loading…
Add table
Add a link
Reference in a new issue