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, direction: Direction,
callback: F 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 { pub fn new (direction: Direction, callback: F) -> Self {
Self { direction, callback, __: Default::default(), } Self { direction, callback, __: Default::default(), }
} }
@ -792,6 +792,12 @@ impl<E, F> Stack<E, F> {
pub fn west (callback: F) -> Self { pub fn west (callback: F) -> Self {
Self::new(West, callback) 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> { 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 { 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>|{ (self.callback)(&mut move |component: &dyn Render<E>|{
let [_, _, w, h] = component.layout([x, y, w_remaining, h_remaining].into()).xywh(); let [_, _, w, h] = component.layout([x, y, w_remaining, h_remaining].into()).xywh();
match self.direction { match self.direction {
South => { South => { y = y.plus(h);
y = y.plus(h);
h_used = h_used.plus(h); h_used = h_used.plus(h);
h_remaining = h_remaining.minus(h); h_remaining = h_remaining.minus(h);
w_used = w_used.max(w); w_used = w_used.max(w); },
}, East => { x = x.plus(w);
East => {
x = x.plus(w);
w_used = w_used.plus(w); w_used = w_used.plus(w);
w_remaining = w_remaining.minus(w); w_remaining = w_remaining.minus(w);
h_used = h_used.max(h); h_used = h_used.max(h); },
}, North | West => { todo!() },
North | West => { Above | Below => {},
todo!()
},
_ => unreachable!(), _ => unreachable!(),
} }
}); });
match self.direction { match self.direction {
North | West => { North | West => { todo!() },
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() },
South | East => {
[to.x(), to.y(), w_used.into(), h_used.into()].into()
},
_ => unreachable!(), _ => 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()); w_used = w_used.plus(layout.h());
to.place(layout, component); to.place(layout, component);
}, },
Above | Below => {
to.place(layout, component);
}
North | West => { North | West => {
todo!() todo!()
}, },