From b801ec88215c7515766cfd95b4dedce8da6ff8e5 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 26 Feb 2024 16:37:59 +0100 Subject: [PATCH] use `derive_setters` --- hui/src/element/builtin/container.rs | 36 +++++++--------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index a41d704..f943f1b 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -19,46 +19,26 @@ use crate::{ //TODO: borders //TODO: min/max size +#[derive(Setters)] +#[setters(prefix = "with_")] pub struct Container { + #[setters(into)] pub size: UiSize2d, pub direction: UiDirection, pub gap: f32, + #[setters(into)] pub padding: Sides, + #[setters(into)] pub align: Alignment2d, + #[setters(into)] pub background: BackgroundColor, + #[setters(into)] pub corner_radius: Corners, + #[setters(skip)] pub children: ElementList, } impl Container { - pub fn with_size(self, size: impl Into) -> Self { - Self { size: size.into(), ..self } - } - - pub fn with_direction(self, direction: UiDirection) -> Self { - Self { direction, ..self } - } - - pub fn with_gap(self, gap: f32) -> Self { - Self { gap, ..self } - } - - pub fn with_padding(self, padding: impl Into>) -> Self { - Self { padding: padding.into(), ..self } - } - - pub fn with_align(self, align: impl Into) -> Self { - Self { align: align.into(), ..self } - } - - pub fn with_background(self, background: impl Into) -> Self { - Self { background: background.into(), ..self } - } - - pub fn with_corner_radius(self, corner_radius: impl Into>) -> Self { - Self { corner_radius: corner_radius.into(), ..self } - } - pub fn with_children(mut self, ui: impl FnOnce(&mut ElementList)) -> Self { self.children.0.extend(ElementList::from_callback(ui).0); self