stack: support above/below

This commit is contained in:
🪞👃🪞 2025-08-10 21:05:05 +03:00
parent 7fd6c91643
commit 35a5784d23

View file

@ -776,7 +776,7 @@ pub struct Stack<E, F> {
direction: Direction,
callback: F
}
impl<E, F> Stack<E, F> {
impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Stack<E, F> {
pub fn new (direction: Direction, callback: F) -> Self {
Self { direction, callback, __: Default::default(), }
}
@ -792,6 +792,12 @@ impl<E, F> Stack<E, F> {
pub fn west (callback: F) -> Self {
Self::new(West, callback)
}
pub fn above (callback: F) -> Self {
Self::new(Above, callback)
}
pub fn below (callback: F) -> Self {
Self::new(Below, callback)
}
}
impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for Stack<E, F> {
fn layout (&self, to: E::Area) -> E::Area {
@ -802,31 +808,23 @@ impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for St
(self.callback)(&mut move |component: &dyn Render<E>|{
let [_, _, w, h] = component.layout([x, y, w_remaining, h_remaining].into()).xywh();
match self.direction {
South => {
y = y.plus(h);
h_used = h_used.plus(h);
h_remaining = h_remaining.minus(h);
w_used = w_used.max(w);
},
East => {
x = x.plus(w);
w_used = w_used.plus(w);
w_remaining = w_remaining.minus(w);
h_used = h_used.max(h);
},
North | West => {
todo!()
},
South => { y = y.plus(h);
h_used = h_used.plus(h);
h_remaining = h_remaining.minus(h);
w_used = w_used.max(w); },
East => { x = x.plus(w);
w_used = w_used.plus(w);
w_remaining = w_remaining.minus(w);
h_used = h_used.max(h); },
North | West => { todo!() },
Above | Below => {},
_ => unreachable!(),
}
});
match self.direction {
North | West => {
todo!()
},
South | East => {
[to.x(), to.y(), w_used.into(), h_used.into()].into()
},
North | West => { todo!() },
South | East => { [to.x(), to.y(), w_used.into(), h_used.into()].into() },
Above | Below => { [to.x(), to.y(), to.w(), to.h()].into() },
_ => unreachable!(),
}
}
@ -850,6 +848,9 @@ impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for St
w_used = w_used.plus(layout.h());
to.place(layout, component);
},
Above | Below => {
to.place(layout, component);
}
North | West => {
todo!()
},