mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
start implementing edn loader; remove PhantomData from some tek_layout constructs
This commit is contained in:
parent
f359768ba2
commit
2b07e7963e
20 changed files with 239 additions and 222 deletions
|
|
@ -18,9 +18,9 @@ impl Direction {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Bsp<E: Engine, X: Content<E>, Y: Content<E>>(Direction, X, Y, PhantomData<E>);
|
||||
pub struct Bsp<X, Y>(Direction, X, Y);
|
||||
|
||||
impl<E: Engine, A: Content<E>, B: Content<E>> Content<E> for Bsp<E, A, B> {
|
||||
impl<E: Engine, 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
|
||||
|
|
@ -35,26 +35,31 @@ impl<E: Engine, A: Content<E>, B: Content<E>> Content<E> for Bsp<E, A, B> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, A: Content<E>, B: Content<E>> Bsp<E, A, B> {
|
||||
pub fn n (a: A, b: B) -> Self { Self(North, a, b, Default::default()) }
|
||||
pub fn s (a: A, b: B) -> Self { Self(South, a, b, Default::default()) }
|
||||
pub fn e (a: A, b: B) -> Self { Self(East, a, b, Default::default()) }
|
||||
pub fn w (a: A, b: B) -> Self { Self(West, a, b, Default::default()) }
|
||||
pub fn a (a: A, b: B) -> Self { Self(Above, a, b, Default::default()) }
|
||||
pub fn b (a: A, b: B) -> Self { Self(Below, a, b, Default::default()) }
|
||||
pub fn contents (&self) -> (&A, &B) { (&self.1, &self.2) }
|
||||
pub fn areas (&self, outer: E::Area) -> [E::Area;3] {
|
||||
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: Engine, A: Content<E>, B: Content<E>> {
|
||||
fn direction (&self) -> Direction;
|
||||
fn contents (&self) -> (&A, &B);
|
||||
fn areas (&self, outer: E::Area) -> [E::Area;3] {
|
||||
let direction = self.direction();
|
||||
let [x, y, w, h] = outer.xywh();
|
||||
let (a, b) = self.contents();
|
||||
let [ax, ay, aw, ah] = a.layout(outer).xywh();
|
||||
let [bx, by, bw, bh] = b.layout(match self.0 {
|
||||
let [bx, by, bw, bh] = b.layout(match direction {
|
||||
Above | Below => outer,
|
||||
South => [x, y + ah, w, h.minus(ah)].into(),
|
||||
North => [x, y, w, h.minus(ah)].into(),
|
||||
East => [x + aw, y, w.minus(aw), h].into(),
|
||||
West => [x, y, w.minus(aw), h].into(),
|
||||
}).xywh();
|
||||
match self.0 {
|
||||
match direction {
|
||||
Above | Below => {
|
||||
let x = ax.min(bx);
|
||||
let w = (ax+aw).max(bx+bw).minus(x);
|
||||
|
|
@ -90,6 +95,11 @@ impl<E: Engine, A: Content<E>, B: Content<E>> Bsp<E, A, B> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, 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,
|
||||
#[macro_export] macro_rules! lay {
|
||||
($($expr:expr),* $(,)?) => {{ let bsp = (); $(let bsp = Bsp::b(bsp, $expr);)*; bsp }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue