use bevy::{
color::palettes::basic::{BLUE, GRAY, LIME, PURPLE, RED, YELLOW},
prelude::*,
};
fn main() {
App::new()
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2d);
commands
.spawn(Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
})
.with_children(|parent| {
parent
.spawn((
Node {
width: px(180),
height: px(100),
..default()
},
BackgroundColor(GRAY.into()),
))
.with_children(|parent| {
parent.spawn((
Node {
position_type: PositionType::Absolute,
left: px(10),
bottom: px(40),
width: px(100),
height: px(50),
..default()
},
BackgroundColor(RED.into()),
));
parent.spawn((
Node {
position_type: PositionType::Absolute,
left: px(45),
bottom: px(30),
width: px(100),
height: px(50),
..default()
},
ZIndex(2),
BackgroundColor(BLUE.into()),
));
parent.spawn((
Node {
position_type: PositionType::Absolute,
left: px(70),
bottom: px(20),
width: px(100),
height: px(75),
..default()
},
ZIndex(-1),
BackgroundColor(LIME.into()),
));
parent.spawn((
Node {
position_type: PositionType::Absolute,
left: px(15),
bottom: px(10),
width: px(100),
height: px(60),
..default()
},
BackgroundColor(PURPLE.into()),
GlobalZIndex(1),
));
parent.spawn((
Node {
position_type: PositionType::Absolute,
left: px(-15),
bottom: px(-15),
width: px(100),
height: px(125),
..default()
},
BackgroundColor(YELLOW.into()),
GlobalZIndex(-1),
));
});
});
}