use bevy::prelude::*;
#[derive(Component)]
pub struct RootMarker;
#[derive(Bundle)]
pub struct Root {
node: Node,
background_color: BackgroundColor,
marker: RootMarker,
transform: Transform,
visibility: Visibility,
}
impl Default for Root {
fn default() -> Self {
Self {
node: Node {
height: Val::Percent(100.0),
width: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor::DEFAULT,
marker: RootMarker,
transform: Transform::default(),
visibility: Visibility::default(),
}
}
}
impl Root {
pub fn new() -> Self {
Root::default()
}
pub fn background_color(mut self, color: Color) -> Self {
self.background_color = color.into();
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 padding(mut self, padding: UiRect) -> Self {
self.node.padding = padding;
self
}
}