fix x/y/xy ops; remove button_2/3

This commit is contained in:
facile pop culture reference 2026-08-08 21:46:05 +03:00
parent 799e497622
commit de591addb3
7 changed files with 138 additions and 144 deletions

View file

@ -1,5 +1,49 @@
use super::*;
pub fn iter_south <'a, S: Screen, D: Draw<S>, I: Iterator<Item = D>> (
iter: impl Fn()->I
) -> impl Draw<S> {
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<S>, I: Iterator<Item = D>> (
iter: impl Fn()->I
) -> impl Draw<S> {
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<Item = D>, U: Draw<S>> (
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
@ -31,40 +75,12 @@ pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
draw(move|_to: &mut S|{ todo!() })
}
pub fn iter_east <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
) -> impl Draw<S> {
draw(move|_to: &mut S|{ todo!() })
}
pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
_height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
) -> impl Draw<S> {
draw(move|_to: &mut S|{ todo!() })
}
pub fn iter_south <'a, S: Screen, D: Draw<S>, I: Iterator<Item = D>> (
iter: impl Fn()->I
) -> impl Draw<S> {
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_south_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
_height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
) -> impl Draw<S> {