use std::marker::PhantomData; use crate::prelude::*; pub struct Stack { pub children: Vec, pub size: StackSize, } impl Widget for Stack { fn draw(&mut self, painter: &mut Painter) { let mut iter = self.children.iter(); if let Some(child) = iter.next() { painter.child_layer(); painter.widget(child); } for child in iter { painter.next_layer(); painter.widget(child); } } fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len { match self.size { StackSize::Default => Len::default(), StackSize::Child(i) => ctx.width(&self.children[i]), } } fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len { match self.size { StackSize::Default => Len::default(), StackSize::Child(i) => ctx.height(&self.children[i]), } } } #[derive(Default, Debug)] pub enum StackSize { #[default] Default, Child(usize), } pub struct StackBuilder, Tag> { pub children: Wa, pub size: StackSize, _pd: PhantomData<(State, Tag)>, } impl, Tag> WidgetFnTrait for StackBuilder { type Widget = Stack; #[track_caller] fn run(self, rsc: &mut Rsc) -> Self::Widget { Stack { children: self.children.add(rsc).arr.into_iter().collect(), size: self.size, } } } impl, Tag> StackBuilder { pub fn new(children: Wa) -> Self { Self { children, size: StackSize::default(), _pd: PhantomData, } } pub fn size(mut self, size: StackSize) -> Self { self.size = size; self } }