removing engine generic from transforms

This commit is contained in:
🪞👃🪞 2025-01-18 02:52:54 +01:00
parent 452bdf9598
commit a949117017
8 changed files with 184 additions and 184 deletions

View file

@ -17,8 +17,8 @@ impl Direction {
}
}
/// A split or layer.
pub struct Bsp<E, X, Y>(PhantomData<E>, Direction, X, Y);
impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<E, A, B> {
pub struct Bsp<X, Y>(Direction, X, Y);
impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<A, B> {
fn layout (&self, outer: E::Area) -> E::Area {
let [_, _, c] = self.areas(outer);
c
@ -26,19 +26,50 @@ impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<E, A, B> {
fn render (&self, to: &mut E) {
let [area_a, area_b, _] = self.areas(to.area());
let (a, b) = self.contents();
match self.1 {
match self.0 {
Below => { to.place(area_a, a); to.place(area_b, b); },
_ => { to.place(area_b, b); to.place(area_a, a); }
}
}
}
impl<E, A, B> Bsp<E, A, B> {
pub fn n (a: A, b: B) -> Self { Self(Default::default(), North, a, b) }
pub fn s (a: A, b: B) -> Self { Self(Default::default(), South, a, b) }
pub fn e (a: A, b: B) -> Self { Self(Default::default(), East, a, b) }
pub fn w (a: A, b: B) -> Self { Self(Default::default(), West, a, b) }
pub fn a (a: A, b: B) -> Self { Self(Default::default(), Above, a, b) }
pub fn b (a: A, b: B) -> Self { Self(Default::default(), Below, a, b) }
try_from_atoms!(<'a, E>: Bsp<RenderBox<'a, E>, RenderBox<'a, E>>: |state, atoms| {
let head = atoms.next()?;
if head.kind() != TokenKind::Key { return None }
match head.text() {
"bsp/n" => return Some(Self::n(
state.get_content(atoms.next()?).expect("no south"),
state.get_content(atoms.next()?).expect("no north")
)),
"bsp/s" => return Some(Self::s(
state.get_content(atoms.next()?).expect("no north"),
state.get_content(atoms.next()?).expect("no south")
)),
"bsp/e" => return Some(Self::e(
state.get_content(atoms.next()?).expect("no west"),
state.get_content(atoms.next()?).expect("no east")
)),
"bsp/w" => return Some(Self::w(
state.get_content(atoms.next()?).expect("no east"),
state.get_content(atoms.next()?).expect("no west")
)),
"bsp/a" => return Some(Self::a(
state.get_content(atoms.next()?).expect("no above"),
state.get_content(atoms.next()?).expect("no below")
)),
"bsp/b" => return Some(Self::b(
state.get_content(atoms.next()?).expect("no above"),
state.get_content(atoms.next()?).expect("no below")
)),
_ => {}
}
});
impl<A, B> Bsp<A, B> {
pub fn n (a: A, b: B) -> Self { Self(North, a, b) }
pub fn s (a: A, b: B) -> Self { Self(South, a, b) }
pub fn e (a: A, b: B) -> Self { Self(East, a, b) }
pub fn w (a: A, b: B) -> Self { Self(West, a, b) }
pub fn a (a: A, b: B) -> Self { Self(Above, a, b) }
pub fn b (a: A, b: B) -> Self { Self(Below, a, b) }
}
pub trait BspAreas<E: Output, A: Content<E>, B: Content<E>> {
fn direction (&self) -> Direction;
@ -89,34 +120,9 @@ pub trait BspAreas<E: Output, A: Content<E>, B: Content<E>> {
}
}
}
impl<E: Output, A: Content<E>, B: Content<E>> BspAreas<E, A, B> for Bsp<E, A, B> {
fn direction (&self) -> Direction { self.1 }
fn contents (&self) -> (&A, &B) { (&self.2, &self.3) }
}
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<'a, T> for Bsp<E, RenderBox<'a, E>, RenderBox<'a, E>> {
fn try_from_atom (s: &'a T, head: &impl Atom, tail: &'a [impl Atom]) -> Option<Self> {
Some(match (head.to_ref(), tail) {
(Key("bsp/n"), [a, b]) => Self::n(
s.get_content(a).expect("no south"),
s.get_content(b).expect("no north")),
(Key("bsp/s"), [a, b]) => Self::s(
s.get_content(a).expect("no north"),
s.get_content(b).expect("no south")),
(Key("bsp/e"), [a, b]) => Self::e(
s.get_content(a).expect("no west"),
s.get_content(b).expect("no east")),
(Key("bsp/w"), [a, b]) => Self::w(
s.get_content(a).expect("no east"),
s.get_content(b).expect("no west")),
(Key("bsp/a"), [a, b]) => Self::a(
s.get_content(a).expect("no above"),
s.get_content(b).expect("no below")),
(Key("bsp/b"), [a, b]) => Self::b(
s.get_content(a).expect("no above"),
s.get_content(b).expect("no below")),
_ => return None
})
}
impl<E: Output, A: Content<E>, B: Content<E>> BspAreas<E, A, B> for Bsp<A, B> {
fn direction (&self) -> Direction { self.0 }
fn contents (&self) -> (&A, &B) { (&self.1, &self.2) }
}
/// Renders multiple things on top of each other,