'and then not have to worry about layout, ever'

This commit is contained in:
🪞👃🪞 2024-12-31 23:58:51 +01:00
parent 21741ebc52
commit f7e6449324
8 changed files with 74 additions and 74 deletions

View file

@ -20,7 +20,7 @@ impl<E: Engine, T: Content<E>> Align<E, T> {
}
impl<E: Engine, T: Content<E>> Content<E> for Align<E, T> {
fn area (&self, outer: E::Area) -> E::Area {
fn layout (&self, outer: E::Area) -> E::Area {
align_areas(self.0, outer.xywh(), Content::area(&self.content(), outer).xywh()).into()
}
fn render (&self, render: &mut E::Output) {
@ -36,20 +36,22 @@ pub fn align_areas<N: Coordinate>(alignment: Alignment, on: [N;4], it: [N;4]) ->
let center_y = center(cfy, cmy, it.y());
let east_x = on.x() + on.w().minus(it.w());
let south_y = on.y() + on.h().minus(it.h());
match alignment {
Alignment::Center => [center_x, center_y, it.w(), it.h()],
Alignment::X => [center_x, it.y(), it.w(), it.h()],
Alignment::Y => [it.x(), center_y, it.w(), it.h()],
let [x, y] = match alignment {
Alignment::Center => [center_x, center_y,],
Alignment::NW => [on.x(), on.y(), it.w(), it.h()],
Alignment::N => [center_x, on.y(), it.w(), it.h()],
Alignment::NE => [east_x, on.y(), it.w(), it.h()],
Alignment::E => [east_x, center_y, it.w(), it.h()],
Alignment::SE => [east_x, south_y, it.w(), it.h()],
Alignment::S => [center_x, south_y, it.w(), it.h()],
Alignment::SW => [on.x(), south_y, it.w(), it.h()],
Alignment::W => [on.x(), center_y, it.w(), it.h()],
}
Alignment::X => [center_x, it.y(), ],
Alignment::Y => [it.x(), center_y,],
Alignment::NW => [on.x(), on.y(), ],
Alignment::N => [center_x, on.y(), ],
Alignment::NE => [east_x, on.y(), ],
Alignment::E => [east_x, center_y,],
Alignment::SE => [east_x, south_y, ],
Alignment::S => [center_x, south_y, ],
Alignment::SW => [on.x(), south_y, ],
Alignment::W => [on.x(), center_y,],
};
[x, y, it.w(), it.h()]
}
//fn align<E: Engine, T: Content<E>, N: Coordinate, R: Area<N> + From<[N;4]>> (align: &Align<E, T>, outer: R, content: R) -> Option<R> {