forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsn.rs
More file actions
61 lines (57 loc) · 1.66 KB
/
bsn.rs
File metadata and controls
61 lines (57 loc) · 1.66 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
50
51
52
53
54
55
56
57
58
59
60
61
//! This example demonstrates how to use BSN to compose scenes.
use bevy::{prelude::*, text::FontSourceTemplate};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, scene.spawn())
.run();
}
fn scene() -> impl SceneList {
bsn_list![Camera2d, ui()]
}
fn ui() -> impl Scene {
bsn! {
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
column_gap: Val::Px(5.),
}
Children [
(
button("Ok")
on(|_event: On<Pointer<Press>>| println!("Ok pressed!"))
),
(
button("Cancel")
on(|_event: On<Pointer<Press>>| println!("Cancel pressed!"))
BackgroundColor(Color::srgb(0.4, 0.15, 0.15))
),
]
}
}
fn button(label: &str) -> impl Scene {
bsn! {
Button
Node {
width: Val::Px(150.0),
height: Val::Px(65.0),
border: UiRect::all(Val::Px(5.0)),
border_radius: BorderRadius::MAX,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
}
BorderColor::from(Color::BLACK)
BackgroundColor(Color::srgb(0.15, 0.15, 0.15))
Children [(
Text(label)
TextFont {
font: FontSourceTemplate::Handle("fonts/FiraSans-Bold.ttf"),
font_size: FontSize::Px(33.0),
}
TextColor(Color::srgb(0.9, 0.9, 0.9))
TextShadow
)]
}
}