use super::*; pub fn iter_south <'a, S: Screen, D: Draw, I: Iterator> ( iter: impl Fn()->I ) -> impl Draw { draw(move|to: &mut S|{ let XYWH(x, y, w, h) = to.area(); let mut y_next = y; let mut h_used = S::Unit::zero(); for item in iter() { let area = XYWH(x, y_next, w, h.minus(h_used)); if let Some(used) = to.draw(area, item)? { let used_h = used.h(); y_next = y_next.plus(used_h); h_used = h_used.plus(used_h); if h_used >= h { break; } } } Ok(Some(XYWH(x, y, w, h_used))) }) } pub fn iter_east <'a, S: Screen, D: Draw, I: Iterator> ( iter: impl Fn()->I ) -> impl Draw { draw(move|to: &mut S|{ let XYWH(x, y, w, h) = to.area(); let mut x_next = x; let mut w_used = S::Unit::zero(); for item in iter() { let area = XYWH(x_next, y, w.minus(w_used), h); if let Some(used) = to.draw(area, item)? { let used_w = used.w(); x_next = x_next.plus(used_w); w_used = w_used.plus(used_w); if w_used >= w { break; } } } Ok(Some(XYWH(x, y, w_used, h))) }) } /// Iterate over a collection of the same kind of [Draw]able: pub fn iter <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, ) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } /// Iterate over a collection of the same kind of [Draw]able: pub fn iter_once <'a, S: Screen, D: 'a, U: Draw> ( _iter: impl Iterator, _draw: impl Fn(D, usize)->U, ) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } /// Iterate over a collection of various [Draw]ables: pub fn iter_dyn < 'a, S: Screen, // Target screen D, // Input doesn't need to be [Draw]able, output does V: Fn()->I, // Function that returns the iterator I: Iterator, // Type of the iterator F: Fn(&D, usize)->dyn Draw, // Function that returns [Draw]able from iterator item > (_items: V, _cb: F) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, ) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, ) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, ) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator, U: Draw> ( _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U, ) -> impl Draw { draw(move|_to: &mut S|{ todo!() }) } pub fn row_south <'a, S: Screen + 'a> (south: S::Unit, height: S::Unit, content: impl Draw) -> impl Draw { content.exact_h(height).push_y(south) } pub fn row_north <'a, S: Screen + 'a> (north: S::Unit, height: S::Unit, content: impl Draw) -> impl Draw { content.exact_h(height).pull_y(north) } pub fn col_east <'a, S: Screen + 'a> (east: S::Unit, width: S::Unit, content: impl Draw) -> impl Draw { content.exact_w(width).push_x(east) } pub fn col_west <'a, S: Screen + 'a> (west: S::Unit, width: S::Unit, content: impl Draw) -> impl Draw { content.exact_w(width).pull_x(west) }