-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathbasic.rs
57 lines (51 loc) · 1.71 KB
/
basic.rs
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
//! An example showing a very basic implementation.
use bevy::prelude::*;
use bevy_simple_text_input::{
TextInput, TextInputPlugin, TextInputSubmitEvent, TextInputSystem, TextInputTextColor,
TextInputTextFont,
};
const BORDER_COLOR_ACTIVE: Color = Color::srgb(0.75, 0.52, 0.99);
const TEXT_COLOR: Color = Color::srgb(0.9, 0.9, 0.9);
const BACKGROUND_COLOR: Color = Color::srgb(0.15, 0.15, 0.15);
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(TextInputPlugin)
.add_systems(Startup, setup)
.add_systems(Update, listener.after(TextInputSystem))
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2d);
commands
.spawn(Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
})
.with_children(|parent| {
parent.spawn((
Node {
width: Val::Px(200.0),
border: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
BorderColor(BORDER_COLOR_ACTIVE),
BackgroundColor(BACKGROUND_COLOR),
TextInput,
TextInputTextFont(TextFont {
font_size: 34.,
..default()
}),
TextInputTextColor(TextColor(TEXT_COLOR)),
));
});
}
fn listener(mut events: EventReader<TextInputSubmitEvent>) {
for event in events.read() {
info!("{:?} submitted: {}", event.entity, event.value);
}
}