add root ui node to example
This commit is contained in:
parent
bcfc27483b
commit
4a0f8b8869
@ -27,6 +27,7 @@ impl Color {
|
|||||||
pub const RED: Color = Color::rgb(1.0, 0.0, 0.0);
|
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 GREEN: Color = Color::rgb(0.0, 1.0, 0.0);
|
||||||
pub const BLUE: Color = Color::rgb(0.0, 0.0, 1.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 {
|
pub const fn rgb(r: f32, g: f32, b: f32) -> Color {
|
||||||
Color { r, g, b, a: 1.0 }
|
Color { r, g, b, a: 1.0 }
|
||||||
|
|||||||
@ -57,115 +57,112 @@ fn setup(
|
|||||||
// })
|
// })
|
||||||
// ui camera
|
// ui camera
|
||||||
.entity_with(OrthographicCameraComponents::ui())
|
.entity_with(OrthographicCameraComponents::ui())
|
||||||
// left vertical fill
|
// root node
|
||||||
.entity_with(UiComponents {
|
.entity_with(UiComponents {
|
||||||
node: Node::new(
|
node: Node::new(Anchors::FULL, Margins::default()),
|
||||||
Anchors::LEFT_FULL,
|
material: materials.add(Color::NONE.into()),
|
||||||
Margins::new(10.0, 200.0, 10.0, 10.0),
|
|
||||||
),
|
|
||||||
material: materials.add(Color::rgb(0.02, 0.02, 0.02).into()),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.with_children(|builder| {
|
.with_children(|builder| {
|
||||||
builder.entity_with(LabelComponents {
|
builder
|
||||||
node: Node::new(
|
// left vertical fill
|
||||||
Anchors::TOP_LEFT,
|
.entity_with(UiComponents {
|
||||||
Margins::new(10.0, 200.0, 40.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()),
|
||||||
label: Label {
|
..Default::default()
|
||||||
text: "Text Label".to_string(),
|
})
|
||||||
font: font_handle,
|
.with_children(|builder| {
|
||||||
style: TextStyle {
|
builder.entity_with(LabelComponents {
|
||||||
font_size: 30.0,
|
node: Node::new(Anchors::TOP_LEFT, Margins::new(10.0, 200.0, 40.0, 10.0)),
|
||||||
color: Color::WHITE,
|
label: Label {
|
||||||
},
|
text: "Text Label".to_string(),
|
||||||
},
|
font: font_handle,
|
||||||
..Default::default()
|
style: TextStyle {
|
||||||
})
|
font_size: 30.0,
|
||||||
})
|
color: Color::WHITE,
|
||||||
// right vertical fill
|
},
|
||||||
.entity_with(UiComponents {
|
},
|
||||||
node: Node::new(
|
..Default::default()
|
||||||
Anchors::RIGHT_FULL,
|
})
|
||||||
Margins::new(10.0, 100.0, 100.0, 100.0),
|
})
|
||||||
),
|
// right vertical fill
|
||||||
material: materials.add(Color::rgb(0.02, 0.02, 0.02).into()),
|
.entity_with(UiComponents {
|
||||||
..Default::default()
|
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()),
|
||||||
// render order test: reddest in the back, whitest in the front
|
..Default::default()
|
||||||
.entity_with(UiComponents {
|
})
|
||||||
node: Node::positioned(
|
// render order test: reddest in the back, whitest in the front
|
||||||
math::vec2(75.0, 60.0),
|
.entity_with(UiComponents {
|
||||||
Anchors::CENTER,
|
node: Node::positioned(
|
||||||
Margins::new(0.0, 100.0, 0.0, 100.0),
|
math::vec2(75.0, 60.0),
|
||||||
),
|
Anchors::CENTER,
|
||||||
material: materials.add(Color::rgb(1.0, 0.0, 0.0).into()),
|
Margins::new(0.0, 100.0, 0.0, 100.0),
|
||||||
..Default::default()
|
),
|
||||||
})
|
material: materials.add(Color::rgb(1.0, 0.0, 0.0).into()),
|
||||||
.entity_with(UiComponents {
|
..Default::default()
|
||||||
node: Node::positioned(
|
})
|
||||||
math::vec2(50.0, 35.0),
|
.entity_with(UiComponents {
|
||||||
Anchors::CENTER,
|
node: Node::positioned(
|
||||||
Margins::new(0.0, 100.0, 0.0, 100.0),
|
math::vec2(50.0, 35.0),
|
||||||
),
|
Anchors::CENTER,
|
||||||
material: materials.add(Color::rgb(1.0, 0.3, 0.3).into()),
|
Margins::new(0.0, 100.0, 0.0, 100.0),
|
||||||
..Default::default()
|
),
|
||||||
})
|
material: materials.add(Color::rgb(1.0, 0.3, 0.3).into()),
|
||||||
.entity_with(UiComponents {
|
..Default::default()
|
||||||
node: Node::positioned(
|
})
|
||||||
math::vec2(100.0, 85.0),
|
.entity_with(UiComponents {
|
||||||
Anchors::CENTER,
|
node: Node::positioned(
|
||||||
Margins::new(0.0, 100.0, 0.0, 100.0),
|
math::vec2(100.0, 85.0),
|
||||||
),
|
Anchors::CENTER,
|
||||||
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
|
Margins::new(0.0, 100.0, 0.0, 100.0),
|
||||||
..Default::default()
|
),
|
||||||
})
|
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
|
||||||
.entity_with(UiComponents {
|
..Default::default()
|
||||||
node: Node::positioned(
|
})
|
||||||
math::vec2(150.0, 135.0),
|
.entity_with(UiComponents {
|
||||||
Anchors::CENTER,
|
node: Node::positioned(
|
||||||
Margins::new(0.0, 100.0, 0.0, 100.0),
|
math::vec2(150.0, 135.0),
|
||||||
),
|
Anchors::CENTER,
|
||||||
material: materials.add(Color::rgb(1.0, 0.7, 0.7).into()),
|
Margins::new(0.0, 100.0, 0.0, 100.0),
|
||||||
..Default::default()
|
),
|
||||||
})
|
material: materials.add(Color::rgb(1.0, 0.7, 0.7).into()),
|
||||||
// parenting
|
..Default::default()
|
||||||
.entity_with(UiComponents {
|
})
|
||||||
node: Node::positioned(
|
// parenting
|
||||||
math::vec2(210.0, 0.0),
|
.entity_with(UiComponents {
|
||||||
Anchors::BOTTOM_LEFT,
|
node: Node::positioned(
|
||||||
Margins::new(0.0, 200.0, 10.0, 210.0),
|
math::vec2(210.0, 0.0),
|
||||||
),
|
Anchors::BOTTOM_LEFT,
|
||||||
material: materials.add(Color::rgb(0.1, 0.1, 1.0).into()),
|
Margins::new(0.0, 200.0, 10.0, 210.0),
|
||||||
..Default::default()
|
),
|
||||||
})
|
material: materials.add(Color::rgb(0.1, 0.1, 1.0).into()),
|
||||||
.with_children(|builder| {
|
..Default::default()
|
||||||
builder.entity_with(UiComponents {
|
})
|
||||||
node: Node::new(
|
.with_children(|builder| {
|
||||||
Anchors::FULL,
|
builder.entity_with(UiComponents {
|
||||||
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()),
|
||||||
material: materials.add(Color::rgb(0.6, 0.6, 1.0).into()),
|
..Default::default()
|
||||||
..Default::default()
|
})
|
||||||
})
|
})
|
||||||
})
|
// alpha test
|
||||||
// alpha test
|
.entity_with(UiComponents {
|
||||||
.entity_with(UiComponents {
|
node: Node::positioned(
|
||||||
node: Node::positioned(
|
math::vec2(200.0, 185.0),
|
||||||
math::vec2(200.0, 185.0),
|
Anchors::CENTER,
|
||||||
Anchors::CENTER,
|
Margins::new(0.0, 100.0, 0.0, 100.0),
|
||||||
Margins::new(0.0, 100.0, 0.0, 100.0),
|
),
|
||||||
),
|
material: materials.add(Color::rgba(1.0, 0.9, 0.9, 0.4).into()),
|
||||||
material: materials.add(Color::rgba(1.0, 0.9, 0.9, 0.4).into()),
|
..Default::default()
|
||||||
..Default::default()
|
})
|
||||||
})
|
// texture
|
||||||
// texture
|
.entity_with(UiComponents {
|
||||||
.entity_with(UiComponents {
|
node: Node::new(
|
||||||
node: Node::new(
|
Anchors::CENTER_TOP,
|
||||||
Anchors::CENTER_TOP,
|
Margins::new(-250.0, 250.0, 510.0 * aspect, 10.0),
|
||||||
Margins::new(-250.0, 250.0, 510.0 * aspect, 10.0),
|
),
|
||||||
),
|
material: materials.add(ColorMaterial::texture(texture_handle)),
|
||||||
material: materials.add(ColorMaterial::texture(texture_handle)),
|
..Default::default()
|
||||||
..Default::default()
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user