use elvis_core::{
derive::{Setter, Wrapper},
option_to_style,
style::{Border, Style},
value::{layouts::Alignment, BoxShadow, Color, Unit, VecUnit},
Node, StyleWrapper,
};
#[derive(Default, Setter, Wrapper)]
pub struct Container {
pub child: Node,
pub align: Option<Alignment>,
pub height: Option<Unit>,
pub max_height: Option<Unit>,
pub max_width: Option<Unit>,
pub width: Option<Unit>,
pub padding: Option<VecUnit>,
pub margin: Option<VecUnit>,
pub background_color: Option<Color>,
pub border: Option<Border>,
pub shadow: Option<BoxShadow>,
}
impl Container {
pub fn with(child: impl Into<Node>) -> Container {
Container::new().child(child)
}
}
impl Into<Node> for Container {
fn into(self) -> Node {
let mut styles: Vec<Style> = vec![];
option_to_style! {
styles, [
(Height, self.height),
(Width, self.width),
(MaxHeight, self.max_height),
(MaxWidth, self.max_width),
(Padding, self.padding),
(Margin, self.margin),
(BackgroundColor, self.background_color),
(BoxShadow, self.shadow),
],[
self.align,
self.border,
],
}
Node::default().style(styles).children(vec![self.child])
}
}