diff --git a/src/draw.rs b/src/draw.rs index b92b229..6a7bc5b 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -94,6 +94,11 @@ pub trait Draw { } } +/// The opposite of [thunk]? +pub fn draw > (item: T) -> impl FnOnce(&mut S) -> Perhaps> { + move|to: &mut S|item.draw(to) +} + pub type Drawn = Perhaps>; impl Draw for () { diff --git a/src/draw/layout.rs b/src/draw/layout.rs index 6c0eb2a..a5eff9f 100644 --- a/src/draw/layout.rs +++ b/src/draw/layout.rs @@ -1,5 +1,7 @@ use crate::*; +impl> Layout for T {} + pub trait Layout: Draw + Sized { fn full_w (self) -> impl Draw { Full::W(self) @@ -11,12 +13,15 @@ pub trait Layout: Draw + Sized { Full::WH(self) } + /// (bsp/e (exact/w 10 "Hello") "World") fn exact_w >> (self, x: N) -> impl Draw { Exact::W(self, x.into()) } + /// (bsp/s (exact/h 10 "Hello") "World") fn exact_h >> (self, y: N) -> impl Draw { Exact::H(self, y.into()) } + /// (exact/wh 10 2 "Hello World") fn exact_wh >> (self, x: N, y: N) -> impl Draw { Exact::WH(self, x.into(), y.into()) } @@ -150,8 +155,6 @@ pub trait Layout: Draw + Sized { } } -impl> Layout for T {} - /// Use whole drawing area along one or both axes. /// /// ``` @@ -279,8 +282,24 @@ pub enum Max, X: Into>> { WH(I, X, X), } -impl_draw!(, X: Into>,>|self: Max, _to: T|{ - todo!() +impl_draw!(, X: Into>,>|self: Max, to: T|{ + let area: XYWH = 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. diff --git a/src/draw/split.rs b/src/draw/split.rs index 11e38a1..8408f57 100644 --- a/src/draw/split.rs +++ b/src/draw/split.rs @@ -141,7 +141,6 @@ fn draw_stacks ( }) } - fn stack_areas ( split: &Split, area: XYWH, diff --git a/src/eval.rs b/src/eval.rs index 2debaa1..35ec582 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -128,21 +128,25 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( let arg2 = tail1.head(); // First `frags.next()` calls returns the namespace. match frags.next() { + Some("when") => when( state.namespace(arg0?)?.unwrap(), thunk(move|output: &mut O|{state.interpret(output, &arg1)}) ).draw(output), + Some("either") => either( state.namespace(arg0?)?.unwrap(), thunk(move|output: &mut O|{state.interpret(output, &arg1)}), thunk(move|output: &mut O|{state.interpret(output, &arg2)}), ).draw(output), + Some("bsp") => eval_enum!("bsp", output, state, frags.next(), arg0, Split { "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, &arg1)}), ).draw(output), + Some("align") => thunk(move|output: &mut O|{ state.interpret(output, &arg0) }).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, "nw" => NW, "sw" => SW, "ne" => NE, "se" => SE, })).draw(output), + Some("exact") => eval_xy!( "exact" => expr, head, output, state, frags.next(), exact_wh, exact_w, exact_h, arg0, arg1, arg2, ), + Some("fixed") => eval_xy!( "fixed" => expr, head, output, state, frags.next(), exact_wh, exact_w, exact_h, arg0, arg1, arg2, ), + Some("min") => eval_xy!( "min" => expr, head, output, state, frags.next(), min_wh, min_w, min_h, arg0, arg1, arg2, ), + Some("max") => eval_xy!( "max" => expr, head, output, state, frags.next(), max_wh, max_w, max_h, arg0, arg1, arg2, ), + Some("push") => eval_xy!( "push" => expr, head, output, state, frags.next(), push_xy, push_x, push_y, arg0, arg1, arg2, ), + Some("fill") => eval_xy!( "fill" => expr, head, output, state, frags.next(), full_wh, full_w, full_h, arg0, ), + _ => return Ok(None) }