forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixed_node.rs
More file actions
49 lines (45 loc) · 1.38 KB
/
Copy pathfixed_node.rs
File metadata and controls
49 lines (45 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Demonstrates how to use `FixedNode` to lay out a UI node as a root node
use bevy::color::palettes::css::BLUE;
use bevy::color::palettes::css::RED;
use bevy::color::palettes::css::YELLOW;
use bevy::prelude::*;
fn main() {
App::new()
.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()
},
BackgroundColor(BLUE.into()),
Pickable::IGNORE,
children![(
FixedNode,
Node {
width: px(100),
height: px(100),
..default()
},
BackgroundColor(YELLOW.into()),
)],
))
.observe(
|over: On<Pointer<Over>>, mut colors: Query<&mut BackgroundColor>| {
colors.get_mut(over.entity).unwrap().0 = RED.into();
},
)
.observe(
|over: On<Pointer<Leave>>, mut colors: Query<&mut BackgroundColor>| {
colors.get_mut(over.entity).unwrap().0 = BLUE.into();
},
);
}