use crate::*; pub fn map_south( item_offset: O::Unit, item_height: O::Unit, item: impl Content ) -> impl Content { Push::y(item_offset, Align::n(Fixed::y(item_height, Fill::x(item)))) } pub struct Map<'a, A, B, I, F, G>(pub PhantomData<&'a()>, pub F, pub G) where I: Iterator + Send + Sync, F: Fn() -> I + Send + Sync + 'a, G: Fn(A, usize)->B + Send + Sync; impl<'a, A, B, I, F, G> Map<'a, A, B, I, F, G> where I: Iterator + Send + Sync, F: Fn() -> I + Send + Sync + 'a, G: Fn(A, usize)->B + Send + Sync { pub fn new (f: F, g: G) -> Self { Self(Default::default(), f, g) } } impl<'a, E, A, B, I, F, G> Content for Map<'a, A, B, I, F, G> where E: Output, B: Render, I: Iterator + Send + Sync, F: Fn() -> I + Send + Sync + 'a, G: Fn(A, usize)->B + Send + Sync { fn layout (&self, area: E::Area) -> E::Area { let Self(_, get_iterator, callback) = self; let mut index = 0; let [mut min_x, mut min_y] = area.center(); let [mut max_x, mut max_y] = area.center(); for item in get_iterator() { let area = callback(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; } 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) { let Self(_, get_iterator, callback) = self; let mut index = 0; //let area = self.layout(to.area()); for item in get_iterator() { let item = callback(item, index); //to.place(area.into(), &item); to.place(item.layout(to.area()), &item); index += 1; } } }