wip: fixing Map, centering

This commit is contained in:
🪞👃🪞 2025-01-01 17:00:28 +01:00
parent 059ff2ca79
commit d17d20e7db
10 changed files with 104 additions and 78 deletions

View file

@ -90,6 +90,9 @@ pub trait Area<N: Coordinate> {
Ok(self)
}
}
#[inline] fn xy (&self) -> [N;2] {
[self.x(), self.y()]
}
#[inline] fn wh (&self) -> [N;2] {
[self.w(), self.h()]
}
@ -121,7 +124,10 @@ pub trait Area<N: Coordinate> {
[self.x(), self.x2(), self.y(), self.y2()]
}
#[inline] fn center (&self) -> [N;2] {
[self.x() + self.w() / 2.into(), self.y() + self.h() / 2.into()]
[self.x() + self.w()/2.into(), self.y() + self.h()/2.into()]
}
#[inline] fn centered (&self) -> [N;2] {
[self.x().minus(self.w()/2.into()), self.y().minus(self.h()/2.into())]
}
fn zero () -> [N;4] {
[N::zero(), N::zero(), N::zero(), N::zero()]

View file

@ -30,16 +30,13 @@ pub trait Content<E: Engine>: Send + Sync {
}
}
/// The platonic ideal item of content: emptiness at dead center.
/// The platonic ideal unit of [Content]: total emptiness at dead center.
impl<E: Engine> Content<E> for () {
fn layout (&self, area: E::Area) -> E::Area {
let [x, y, w, h] = area.xywh();
let x = x + w / 2.into();
let y = y + h / 2.into();
let [x, y] = area.center();
[x, y, 0.into(), 0.into()].into()
}
fn render (&self, _: &mut E::Output) {
}
fn render (&self, _: &mut E::Output) {}
}
impl<E: Engine, T: Content<E>> Content<E> for &T {