use bevy::prelude::*;
#[derive(Bundle)]
pub struct Container {
node: Node,
background_color: BackgroundColor,
transform: Transform,
visibility: Visibility,
}
impl Default for Container {
fn default() -> Self {
Container {
node: Node {
height: Val::Auto,
width: Val::Auto,
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor::DEFAULT,
transform: Transform::default(),
visibility: Visibility::default(),
}
}
}
impl Container {
pub fn new() -> Self {
Container::default()
}
pub fn width(width: Val) -> Self {
let mut container = Self::default();
container.node.width = width;
container
}
pub fn height(height: Val) -> Self {
let mut container = Self::default();
container.node.height = height;
container
}
pub fn size(width: Val, height: Val) -> Self {
let mut container = Self::default();
container.node.width = width;
container.node.height = height;
container
}
pub fn background_color(mut self, color: Color) -> Self {
self.background_color = color.into();
self
}
pub fn absolute(mut self) -> Self {
self.node.position_type = PositionType::Absolute;
self
}
pub fn row(mut self) -> Self {
self.node.flex_direction = FlexDirection::Row;
self
}
pub fn justify_start(mut self) -> Self {
self.node.justify_content = JustifyContent::FlexStart;
self
}
pub fn justify_end(mut self) -> Self {
self.node.justify_content = JustifyContent::FlexEnd;
self
}
pub fn justify_between(mut self) -> Self {
self.node.justify_content = JustifyContent::SpaceBetween;
self
}
pub fn justify_around(mut self) -> Self {
self.node.justify_content = JustifyContent::SpaceAround;
self
}
pub fn items_start(mut self) -> Self {
self.node.align_items = AlignItems::FlexStart;
self
}
pub fn items_end(mut self) -> Self {
self.node.align_items = AlignItems::FlexEnd;
self
}
pub fn content_start(mut self) -> Self {
self.node.align_content = AlignContent::FlexStart;
self
}
pub fn wrap(mut self) -> Self {
self.node.flex_wrap = FlexWrap::Wrap;
self
}
pub fn padding(mut self, padding: UiRect) -> Self {
self.node.padding = padding;
self
}
pub fn margin(mut self, margin: UiRect) -> Self {
self.node.margin = margin;
self
}
}