mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
wip: enable stack
This commit is contained in:
parent
c0d6d0174e
commit
ca049bff2b
4 changed files with 40 additions and 6 deletions
|
|
@ -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>>;
|
||||
|
||||
impl<S: Screen> Draw<S> for () {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use crate::*;
|
||||
|
||||
impl<S: Screen, T: Draw<S>> Layout<S> for T {}
|
||||
|
||||
pub trait Layout<S: Screen>: Draw<S> + Sized {
|
||||
fn full_w (self) -> impl Draw<S> {
|
||||
Full::W(self)
|
||||
|
|
@ -11,12 +13,15 @@ pub trait Layout<S: Screen>: Draw<S> + Sized {
|
|||
Full::WH(self)
|
||||
}
|
||||
|
||||
/// (bsp/e (exact/w 10 "Hello") "World")
|
||||
fn exact_w <N: Into<Option<S::Unit>>> (self, x: N) -> impl Draw<S> {
|
||||
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> {
|
||||
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> {
|
||||
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.
|
||||
///
|
||||
/// ```
|
||||
|
|
@ -279,8 +282,24 @@ pub enum Max<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>> {
|
|||
WH(I, X, X),
|
||||
}
|
||||
|
||||
impl_draw!(<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>,>|self: Max<T, I, X>, _to: T|{
|
||||
todo!()
|
||||
impl_draw!(<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>,>|self: Max<T, I, X>, to: T|{
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -141,7 +141,6 @@ fn draw_stacks <S: Screen> (
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
fn stack_areas <S: Screen> (
|
||||
split: &Split,
|
||||
area: XYWH<S::Unit>,
|
||||
|
|
|
|||
13
src/eval.rs
13
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)
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue