fix and test alignments

This commit is contained in:
🪞👃🪞 2025-01-01 21:04:39 +01:00
parent 9125e04e07
commit 3c14456566
8 changed files with 135 additions and 100 deletions

View file

@ -94,24 +94,30 @@ impl<E, T, I, J, R, F> Content<E> for Map<E, T, I, J, R, F> where
{
fn layout (&self, area: E::Area) -> E::Area {
let mut index = 0;
let mut max_w = 0;
let mut max_h = 0;
let [mut min_x, mut min_y] = area.center();
let [mut max_x, mut max_y] = area.center();
for item in (self.1)() {
let [x, y, w, h] = (self.2)(item, index).layout(area).xywh();
max_w = max_w.max((x + w).into());
max_h = max_h.max((y + h).into());
let area = (self.2)(item, index).layout(area).xywh();
let [x,y,w,h] = area.xywh();
min_x = min_x.min(x.into());
min_y = min_y.min(y.into());
max_x = max_x.max((x + w).into());
max_y = max_y.max((y + h).into());
index += 1;
}
align_areas(
Alignment::Center,
area.xywh(),
[0.into(), 0.into(), max_w.into(), max_h.into()]
).into()
let w = max_x - min_x;
let h = max_y - min_y;
//[min_x.into(), min_y.into(), w.into(), h.into()].into()
area.center_xy([w.into(), h.into()].into()).into()
}
fn render (&self, to: &mut E::Output) {
let mut index = 0;
let area = self.layout(to.area());
//panic!("{area:?}");
//to.blit(&format!("{area:?}"), 0, 0, None);
for item in (self.1)() {
(self.2)(item, index).render(to);
let item = (self.2)(item, index);
to.place(area.into(), &item);
index += 1;
}
}