mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
generalize Layers
This commit is contained in:
parent
35b37e3e3a
commit
f7b2134310
3 changed files with 53 additions and 33 deletions
|
|
@ -145,6 +145,32 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, F> Widget for Layers<E, F>
|
||||
where
|
||||
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()>
|
||||
{
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Size) -> Perhaps<E::Size> {
|
||||
let mut w: E::Unit = 0.into();
|
||||
let mut h: E::Unit = 0.into();
|
||||
(self.0)(&mut |layer| {
|
||||
if let Some(layer_area) = layer.layout(area)? {
|
||||
w = w.max(layer_area.w());
|
||||
h = h.max(layer_area.h());
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(Some([w, h].into()))
|
||||
}
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
if let Some(size) = self.layout(to.area().wh().into())? {
|
||||
(self.0)(&mut |layer|to.render_in(to.area().clip(size).into(), &layer))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//pub fn collect <'a, E: Engine, const N: usize> (
|
||||
//items: &'a [&'a dyn Widget<Engine = E>;N]
|
||||
//) -> impl Send + Sync + Fn(&'a mut dyn FnMut(&'a dyn Widget<Engine = E>)->Usually<()>)->Usually<()> + '_ {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue