From fb04565f96a6c4ed648c17197c999e400202204f Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Sat, 21 Sep 2024 15:58:36 -0500 Subject: [PATCH] make PaddingElem use Box instead of generics --- src/elems/padding.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/elems/padding.rs b/src/elems/padding.rs index 2b1ba61..9bf527a 100644 --- a/src/elems/padding.rs +++ b/src/elems/padding.rs @@ -27,30 +27,35 @@ impl Padding { } impl Build for Padding { - type Elem = PaddingElem; + type Elem = PaddingElem; fn build(self) -> Self::Elem { PaddingElem { padding_x: self.padding_x, padding_y: self.padding_y, - child: self.child.build(), + child: Box::new(self.child.build()), } } fn rebuild(self, elem: &mut Self::Elem) { elem.padding_x = self.padding_x; elem.padding_y = self.padding_y; - self.child.rebuild(&mut elem.child); + + if let Some(child) = elem.child.downcast_mut() { + self.child.rebuild(child); + } else { + elem.child = Box::new(self.child.build()); + } } } -pub struct PaddingElem { +pub struct PaddingElem { padding_x: f32, padding_y: f32, - child: E, + child: Box, } -impl Elem for PaddingElem { +impl Elem for PaddingElem { fn update(&mut self, cx: &mut Context) { self.child.update(cx); }