mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: bsp custom rendering
This commit is contained in:
parent
d5dd746b35
commit
41f17bb0e7
1 changed files with 42 additions and 10 deletions
|
|
@ -17,16 +17,6 @@ pub enum Bsp<E: Engine, X: Render<E>, Y: Render<E>> {
|
|||
Null(PhantomData<E>),
|
||||
}
|
||||
|
||||
render!(|self:Bsp<E: Engine, X: Render<E>, Y: Render<E>>|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<E: Engine, X: Render<E>, Y: Render<E>> Bsp<E, X, Y> {
|
||||
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<E: Engine, X: Render<E>, Y: Render<E>> Default for Bsp<E, X, Y> {
|
|||
Self::Null(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Render<E>, Y: Render<E>> Render<E> for Bsp<E, X, Y> {
|
||||
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
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!()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue