Skip to content

Commit

Permalink
make PaddingElem use Box<dyn Elem> instead of generics
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Sep 21, 2024
1 parent 444447c commit fb04565
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/elems/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,35 @@ impl<E: Build> Padding<E> {
}

impl<E: Build> Build for Padding<E> {
type Elem = PaddingElem<E::Elem>;
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<E> {
pub struct PaddingElem {
padding_x: f32,
padding_y: f32,
child: E,
child: Box<dyn Elem>,
}

impl<E: Elem> Elem for PaddingElem<E> {
impl Elem for PaddingElem {
fn update(&mut self, cx: &mut Context) {
self.child.update(cx);
}
Expand Down

0 comments on commit fb04565

Please sign in to comment.