use crate::{ geometry::vector::Vector2F, AfterLayoutContext, AppContext, Element, Event, EventContext, LayoutContext, MutableAppContext, PaintContext, SizeConstraint, }; pub struct Stack { children: Vec>, size: Option, } impl Stack { pub fn new() -> Self { Stack { children: Vec::new(), size: None, } } } impl Element for Stack { fn layout( &mut self, constraint: SizeConstraint, ctx: &mut LayoutContext, app: &AppContext, ) -> Vector2F { let mut size = constraint.min; for child in &mut self.children { size = size.max(child.layout(constraint, ctx, app)); } self.size = Some(size); size } fn after_layout(&mut self, ctx: &mut AfterLayoutContext, app: &mut MutableAppContext) { for child in &mut self.children { child.after_layout(ctx, app); } } fn paint(&mut self, origin: Vector2F, ctx: &mut PaintContext, app: &AppContext) { for child in &mut self.children { child.paint(origin, ctx, app); } } fn dispatch_event(&self, event: &Event, ctx: &mut EventContext, app: &AppContext) -> bool { for child in self.children.iter().rev() { if child.dispatch_event(event, ctx, app) { return true; } } false } fn size(&self) -> Option { self.size } } impl Extend> for Stack { fn extend>>(&mut self, children: T) { self.children.extend(children) } }