add root ui node to example

This commit is contained in:
Carter Anderson 2020-06-25 13:19:17 -07:00
parent bcfc27483b
commit 4a0f8b8869
2 changed files with 104 additions and 106 deletions

View File

@ -27,6 +27,7 @@ impl Color {
pub const RED: Color = Color::rgb(1.0, 0.0, 0.0);
pub const GREEN: Color = Color::rgb(0.0, 1.0, 0.0);
pub const BLUE: Color = Color::rgb(0.0, 0.0, 1.0);
pub const NONE: Color = Color::rgba(0.0, 0.0, 0.0, 0.0);
pub const fn rgb(r: f32, g: f32, b: f32) -> Color {
Color { r, g, b, a: 1.0 }

View File

@ -57,21 +57,23 @@ fn setup(
// })
// ui camera
.entity_with(OrthographicCameraComponents::ui())
// root node
.entity_with(UiComponents {
node: Node::new(Anchors::FULL, Margins::default()),
material: materials.add(Color::NONE.into()),
..Default::default()
})
.with_children(|builder| {
builder
// left vertical fill
.entity_with(UiComponents {
node: Node::new(
Anchors::LEFT_FULL,
Margins::new(10.0, 200.0, 10.0, 10.0),
),
node: Node::new(Anchors::LEFT_FULL, Margins::new(10.0, 200.0, 10.0, 10.0)),
material: materials.add(Color::rgb(0.02, 0.02, 0.02).into()),
..Default::default()
})
.with_children(|builder| {
builder.entity_with(LabelComponents {
node: Node::new(
Anchors::TOP_LEFT,
Margins::new(10.0, 200.0, 40.0, 10.0),
),
node: Node::new(Anchors::TOP_LEFT, Margins::new(10.0, 200.0, 40.0, 10.0)),
label: Label {
text: "Text Label".to_string(),
font: font_handle,
@ -85,10 +87,7 @@ fn setup(
})
// right vertical fill
.entity_with(UiComponents {
node: Node::new(
Anchors::RIGHT_FULL,
Margins::new(10.0, 100.0, 100.0, 100.0),
),
node: Node::new(Anchors::RIGHT_FULL, Margins::new(10.0, 100.0, 100.0, 100.0)),
material: materials.add(Color::rgb(0.02, 0.02, 0.02).into()),
..Default::default()
})
@ -141,10 +140,7 @@ fn setup(
})
.with_children(|builder| {
builder.entity_with(UiComponents {
node: Node::new(
Anchors::FULL,
Margins::new(20.0, 20.0, 20.0, 20.0),
),
node: Node::new(Anchors::FULL, Margins::new(20.0, 20.0, 20.0, 20.0)),
material: materials.add(Color::rgb(0.6, 0.6, 1.0).into()),
..Default::default()
})
@ -167,5 +163,6 @@ fn setup(
),
material: materials.add(ColorMaterial::texture(texture_handle)),
..Default::default()
})
});
}