diff --git a/crates/tek/src/layout/bsp.rs b/crates/tek/src/layout/bsp.rs index ad522e6e..68f39d1c 100644 --- a/crates/tek/src/layout/bsp.rs +++ b/crates/tek/src/layout/bsp.rs @@ -17,16 +17,6 @@ pub enum Bsp, Y: Render> { Null(PhantomData), } -render!(|self:Bsp, Y: Render>|render(|to|{Ok(match self { - Bsp::Null(_) => (), - Bsp::N(a, b) => (), - Bsp::S(a, b) => (), - Bsp::E(a, b) => (), - Bsp::W(a, b) => (), - Bsp::A(a, b) => (), - Bsp::B(a, b) => (), -})})); - impl, Y: Render> Bsp { pub fn new (x: X) -> Self { Self::A(Some(x), None) } pub fn n (x: X, y: Y) -> Self { Self::N(Some(x), Some(y)) } @@ -42,3 +32,45 @@ impl, Y: Render> Default for Bsp { Self::Null(Default::default()) } } + +impl, Y: Render> Render for Bsp { + fn min_size (&self, to: E::Size) -> Perhaps { + Ok(Some(match self { + Self::Null(_) => [0.into(), 0.into()].into(), + Self::S(a, b) => { + let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into()); + let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into()); + [a.w().max(b.w()), a.h() + b.h()].into() + }, + Self::W(a, b) => { + let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into()); + let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into()); + [a.w() + b.w(), a.h().max(b.h())].into() + }, + _ => todo!() + })) + } + fn render (&self, to: &mut E::Output) -> Usually<()> { + Ok(match self { + Self::Null(_) => {}, + Self::S(a, b) => { + let n = [0.into(), 0.into()].into(); + let s = to.area().wh().into(); + let s_a = a.min_size(s)?.unwrap_or(n); + let s_b = b.min_size(s)?.unwrap_or(n); + to.render_in(to.area().clip(s_a).into(), a)?; + to.render_in(to.area().push_y(s_a.h().into()).into(), b)?; + }, + Self::W(a, b) => { + let n = [0.into(), 0.into()].into(); + let s = to.area().wh().into(); + let s_a = a.min_size(s)?.unwrap_or(n); + let s_b = b.min_size(s)?.unwrap_or(n); + let s_x = (to.area().w() - s_a.w()).into(); + to.render_in(to.area().push_x(s_x).into(), a)?; + to.render_in(to.area().shrink_x(s_x).into(), b)?; + }, + _ => todo!() + }) + } +}