wip: enable stack

This commit is contained in:
facile pop culture reference 2026-07-26 22:34:17 +03:00
parent c0d6d0174e
commit ca049bff2b
4 changed files with 40 additions and 6 deletions

View file

@ -94,6 +94,11 @@ pub trait Draw<S: Screen> {
} }
} }
/// The opposite of [thunk]?
pub fn draw <S: Screen, T: Draw<S>> (item: T) -> impl FnOnce(&mut S) -> Perhaps<XYWH<S::Unit>> {
move|to: &mut S|item.draw(to)
}
pub type Drawn<U> = Perhaps<XYWH<U>>; pub type Drawn<U> = Perhaps<XYWH<U>>;
impl<S: Screen> Draw<S> for () { impl<S: Screen> Draw<S> for () {

View file

@ -1,5 +1,7 @@
use crate::*; use crate::*;
impl<S: Screen, T: Draw<S>> Layout<S> for T {}
pub trait Layout<S: Screen>: Draw<S> + Sized { pub trait Layout<S: Screen>: Draw<S> + Sized {
fn full_w (self) -> impl Draw<S> { fn full_w (self) -> impl Draw<S> {
Full::W(self) Full::W(self)
@ -11,12 +13,15 @@ pub trait Layout<S: Screen>: Draw<S> + Sized {
Full::WH(self) Full::WH(self)
} }
/// (bsp/e (exact/w 10 "Hello") "World")
fn exact_w <N: Into<Option<S::Unit>>> (self, x: N) -> impl Draw<S> { fn exact_w <N: Into<Option<S::Unit>>> (self, x: N) -> impl Draw<S> {
Exact::W(self, x.into()) Exact::W(self, x.into())
} }
/// (bsp/s (exact/h 10 "Hello") "World")
fn exact_h <N: Into<Option<S::Unit>>> (self, y: N) -> impl Draw<S> { fn exact_h <N: Into<Option<S::Unit>>> (self, y: N) -> impl Draw<S> {
Exact::H(self, y.into()) Exact::H(self, y.into())
} }
/// (exact/wh 10 2 "Hello World")
fn exact_wh <N: Into<Option<S::Unit>>> (self, x: N, y: N) -> impl Draw<S> { fn exact_wh <N: Into<Option<S::Unit>>> (self, x: N, y: N) -> impl Draw<S> {
Exact::WH(self, x.into(), y.into()) Exact::WH(self, x.into(), y.into())
} }
@ -150,8 +155,6 @@ pub trait Layout<S: Screen>: Draw<S> + Sized {
} }
} }
impl<S: Screen, T: Draw<S>> Layout<S> for T {}
/// Use whole drawing area along one or both axes. /// Use whole drawing area along one or both axes.
/// ///
/// ``` /// ```
@ -279,8 +282,24 @@ pub enum Max<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>> {
WH(I, X, X), WH(I, X, X),
} }
impl_draw!(<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>,>|self: Max<T, I, X>, _to: T|{ impl_draw!(<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>,>|self: Max<T, I, X>, to: T|{
todo!() let area: XYWH<T::Unit> = to.area();
let (item, area) = match self {
Self::W(item, max_w) => (item, XYWH(
area.0, area.1, max_w.into().map(|max|max.min(area.2)).unwrap_or(area.2),
area.3
)),
Self::H(item, max_h) => (item, XYWH(
area.0, area.1, area.2,
max_h.into().map(|max|max.min(area.3)).unwrap_or(area.3)
)),
Self::WH(item, max_w, max_h) => (item, XYWH(
area.0, area.1, max_w.into().map(|max|max.min(area.2)).unwrap_or(area.2),
max_h.into().map(|max|max.min(area.3)).unwrap_or(area.3)
)),
_ => return Ok(None)
};
to.clip(area, draw(item))
}); });
/// Set size of of drawing area. /// Set size of of drawing area.

View file

@ -141,7 +141,6 @@ fn draw_stacks <S: Screen> (
}) })
} }
fn stack_areas <S: Screen> ( fn stack_areas <S: Screen> (
split: &Split, split: &Split,
area: XYWH<S::Unit>, area: XYWH<S::Unit>,

View file

@ -128,21 +128,25 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
let arg2 = tail1.head(); let arg2 = tail1.head();
// First `frags.next()` calls returns the namespace. // First `frags.next()` calls returns the namespace.
match frags.next() { match frags.next() {
Some("when") => when( Some("when") => when(
state.namespace(arg0?)?.unwrap(), state.namespace(arg0?)?.unwrap(),
thunk(move|output: &mut O|{state.interpret(output, &arg1)}) thunk(move|output: &mut O|{state.interpret(output, &arg1)})
).draw(output), ).draw(output),
Some("either") => either( Some("either") => either(
state.namespace(arg0?)?.unwrap(), state.namespace(arg0?)?.unwrap(),
thunk(move|output: &mut O|{state.interpret(output, &arg1)}), thunk(move|output: &mut O|{state.interpret(output, &arg1)}),
thunk(move|output: &mut O|{state.interpret(output, &arg2)}), thunk(move|output: &mut O|{state.interpret(output, &arg2)}),
).draw(output), ).draw(output),
Some("bsp") => eval_enum!("bsp", output, state, frags.next(), arg0, Split { Some("bsp") => eval_enum!("bsp", output, state, frags.next(), arg0, Split {
"n" => North, "s" => South, "e" => East, "w" => West, "a" => Above, "b" => Below "n" => North, "s" => South, "e" => East, "w" => West, "a" => Above, "b" => Below
}).half( }).stack(
thunk(move|output: &mut O|{state.interpret(output, &arg0)}), thunk(move|output: &mut O|{state.interpret(output, &arg0)}),
thunk(move|output: &mut O|{state.interpret(output, &arg1)}), thunk(move|output: &mut O|{state.interpret(output, &arg1)}),
).draw(output), ).draw(output),
Some("align") => thunk(move|output: &mut O|{ Some("align") => thunk(move|output: &mut O|{
state.interpret(output, &arg0) state.interpret(output, &arg0)
}).align(eval_enum!("align", output, state, frags.next(), arg0, Azimuth { }).align(eval_enum!("align", output, state, frags.next(), arg0, Azimuth {
@ -150,24 +154,31 @@ pub fn eval_view <'a, O: Screen + 'a, S> (
"n" => N, "s" => S, "e" => E, "w" => W, "n" => N, "s" => S, "e" => E, "w" => W,
"nw" => NW, "sw" => SW, "ne" => NE, "se" => SE, "nw" => NW, "sw" => SW, "ne" => NE, "se" => SE,
})).draw(output), })).draw(output),
Some("exact") => eval_xy!( Some("exact") => eval_xy!(
"exact" => expr, head, output, state, frags.next(), exact_wh, exact_w, exact_h, arg0, arg1, arg2, "exact" => expr, head, output, state, frags.next(), exact_wh, exact_w, exact_h, arg0, arg1, arg2,
), ),
Some("fixed") => eval_xy!( Some("fixed") => eval_xy!(
"fixed" => expr, head, output, state, frags.next(), exact_wh, exact_w, exact_h, arg0, arg1, arg2, "fixed" => expr, head, output, state, frags.next(), exact_wh, exact_w, exact_h, arg0, arg1, arg2,
), ),
Some("min") => eval_xy!( Some("min") => eval_xy!(
"min" => expr, head, output, state, frags.next(), min_wh, min_w, min_h, arg0, arg1, arg2, "min" => expr, head, output, state, frags.next(), min_wh, min_w, min_h, arg0, arg1, arg2,
), ),
Some("max") => eval_xy!( Some("max") => eval_xy!(
"max" => expr, head, output, state, frags.next(), max_wh, max_w, max_h, arg0, arg1, arg2, "max" => expr, head, output, state, frags.next(), max_wh, max_w, max_h, arg0, arg1, arg2,
), ),
Some("push") => eval_xy!( Some("push") => eval_xy!(
"push" => expr, head, output, state, frags.next(), push_xy, push_x, push_y, arg0, arg1, arg2, "push" => expr, head, output, state, frags.next(), push_xy, push_x, push_y, arg0, arg1, arg2,
), ),
Some("fill") => eval_xy!( Some("fill") => eval_xy!(
"fill" => expr, head, output, state, frags.next(), full_wh, full_w, full_h, arg0, "fill" => expr, head, output, state, frags.next(), full_wh, full_w, full_h, arg0,
), ),
_ => return Ok(None) _ => return Ok(None)
} }