mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 05:16:44 +02:00
fix x/y/xy ops; remove button_2/3
This commit is contained in:
parent
799e497622
commit
de591addb3
7 changed files with 138 additions and 144 deletions
|
|
@ -35,14 +35,23 @@ impl_draw!(<T: Screen, I: Draw<T>,>|self: Full<T, I>, to: T|{
|
|||
def_layout_modifier!(
|
||||
LayoutExact (exact_w exact_h exact_wh),
|
||||
Exact { W H WH } kw_exact "exact" |self, to| {
|
||||
let XYWH(x, y, w0, h0) = to.area();
|
||||
let (item, w, h) = match self {
|
||||
Self::W(item, w) => (item, (*w).into(), None),
|
||||
Self::H(item, h) => (item, None, (*h).into()),
|
||||
Self::WH(item, w, h) => (item, (*w).into(), (*h).into()),
|
||||
_ => return Ok(None)
|
||||
let XYWH(x0, y0, w0, h0) = to.area();
|
||||
let (item, w1, h1) = match self {
|
||||
Self::W(item, w1) => (item, (*w1).into(), None),
|
||||
Self::H(item, h1) => (item, None, (*h1).into()),
|
||||
Self::WH(item, w1, h1) => (item, (*w1).into(), (*h1).into()),
|
||||
_ => unreachable!()
|
||||
};
|
||||
to.draw(XYWH(x, y, w.unwrap_or(w0), h.unwrap_or(h0)), item)
|
||||
let w1 = w1.unwrap_or(w0);
|
||||
let h1 = h1.unwrap_or(h0);
|
||||
let area = XYWH(x0, y0, w1, h1);
|
||||
let area = to.draw(area, item)?;
|
||||
Ok(area.map(|XYWH(x2, y2, w2, h2)|match self {
|
||||
Self::W(..) => XYWH(x0, y2, w1, h2),
|
||||
Self::H(..) => XYWH(x2, y0, w2, h1),
|
||||
Self::WH(..) => XYWH(x0, y0, w1, h1),
|
||||
_ => unreachable!()
|
||||
}))
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -192,15 +192,13 @@ fn draw_stacks <S: Screen> (
|
|||
area_b: impl Into<Option<XYWH<S::Unit>>>,
|
||||
origin_b: impl Into<Option<Azimuth>>,
|
||||
) -> Usually<(Option<XYWH<S::Unit>>, Option<XYWH<S::Unit>>)> {
|
||||
let draw_a = |to: &mut S|Ok::<_, Box<dyn Error>>(if let Some(origin_a) = origin_a.into() {
|
||||
to.draw(area_a.into(), a.align(origin_a))?
|
||||
} else {
|
||||
to.draw(area_a.into(), a)?
|
||||
let draw_a = |to: &mut S|Ok::<_, Box<dyn Error>>(match origin_a.into() {
|
||||
Some(origin_a) => to.draw(area_a.into(), a.align(origin_a))?,
|
||||
None => to.draw(area_a.into(), a)?
|
||||
});
|
||||
let draw_b = |to: &mut S|Ok::<_, Box<dyn Error>>(if let Some(origin_b) = origin_b.into() {
|
||||
to.draw(area_b.into(), b.align(origin_b))?
|
||||
} else {
|
||||
to.draw(area_b.into(), b)?
|
||||
let draw_b = |to: &mut S|Ok::<_, Box<dyn Error>>(match origin_b.into() {
|
||||
Some(origin_b) => to.draw(area_b.into(), b.align(origin_b))?,
|
||||
None => to.draw(area_b.into(), b)?
|
||||
});
|
||||
Ok(if matches!(split, Split::Below) {
|
||||
let drawn_b = draw_b(to)?;
|
||||
|
|
@ -217,7 +215,7 @@ pub fn stack_areas <S: Screen> (
|
|||
a: impl Draw<S>,
|
||||
b: impl Draw<S>,
|
||||
) -> Usually<(Option<XYWH<S::Unit>>, Option<XYWH<S::Unit>>)> {
|
||||
let area_a = to.draw(None, a)?;
|
||||
let area_a = to.size(None, a)?;
|
||||
Ok(match split {
|
||||
Split::South => (
|
||||
area_a,
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue