Skip to content

Commit 30ed6bc

Browse files
authored
Merge pull request #10 from fallible-algebra/master
Prepare examples for 0.15
2 parents 4e8bd5e + 162d92b commit 30ed6bc

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ keywords = ["bevy", "http", "plugin", "wasm"]
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15-
bevy_app = "0.14.0"
16-
bevy_derive = "0.14.0"
17-
bevy_hierarchy = "0.14.0"
18-
bevy_ecs = { version = "0.14.0", features = ["multi_threaded"] }
19-
bevy_tasks = "0.14.0"
15+
bevy_app = "0.15.0-rc.1"
16+
bevy_derive = "0.15.0-rc.1"
17+
bevy_hierarchy = "0.15.0-rc.1"
18+
bevy_ecs = { version = "0.15.0-rc.1", features = ["multi_threaded"] }
19+
bevy_tasks = "0.15.0-rc.1"
2020

2121
crossbeam-channel = "0.5.11"
2222
ehttp = { version = "0.5.0", features = ["native-async", "json"] }
@@ -27,7 +27,7 @@ serde_json = "1.0"
2727
doctest = false
2828

2929
[dev-dependencies]
30-
bevy = { version = "0.14.0", default-features = false, features = [
30+
bevy = { version = "0.15.0-rc.1", default-features = false, features = [
3131
"animation",
3232
"bevy_asset",
3333
"bevy_gilrs",

examples/window.rs

+45-40
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use bevy_http_client::{
99

1010
fn main() {
1111
App::new()
12-
.insert_resource(Msaa::Off)
1312
.insert_resource(ClearColor(Color::srgb(0.4, 0.4, 0.4)))
1413
.add_plugins(DefaultPlugins.set(WindowPlugin {
1514
primary_window: Some(Window {
@@ -35,69 +34,75 @@ fn main() {
3534
#[derive(Component)]
3635
struct ResponseText;
3736

37+
#[derive(Component)]
38+
struct ResponseIP;
39+
3840
fn setup(mut commands: Commands) {
3941
// Camera
40-
commands.spawn((Camera2dBundle::default(), IsDefaultUiCamera));
41-
42-
let text_section = move |color: Srgba, value: &str| {
43-
TextSection::new(
44-
value,
45-
TextStyle {
46-
font_size: 40.0,
47-
color: color.into(),
48-
..default()
49-
},
50-
)
51-
};
52-
42+
commands.spawn((Camera2d, IsDefaultUiCamera));
5343
commands
54-
.spawn(NodeBundle {
55-
style: Style {
44+
.spawn((
45+
Node {
5646
position_type: PositionType::Absolute,
5747
padding: UiRect::all(Val::Px(5.0)),
48+
display: Display::Grid,
5849
..default()
5950
},
60-
z_index: ZIndex::Global(i32::MAX),
61-
background_color: Color::BLACK.with_alpha(0.75).into(),
62-
..default()
63-
})
64-
.with_children(|c| {
65-
c.spawn((
66-
TextBundle::from_sections([
67-
text_section(LIME, "Status: "),
68-
text_section(AQUA, ""),
69-
text_section(LIME, "\nIp: "),
70-
text_section(AQUA, ""),
71-
]),
72-
ResponseText,
73-
));
51+
ZIndex(i32::MAX),
52+
BackgroundColor(Color::BLACK.with_alpha(0.75)),
53+
))
54+
.with_children(|parent| {
55+
let text_font = TextFont {
56+
font_size: 40.,
57+
..default()
58+
};
59+
parent.spawn(Node::default()).with_children(|parent| {
60+
parent.spawn((
61+
Text::new("Status: "),
62+
TextColor(LIME.into()),
63+
text_font.clone(),
64+
));
65+
parent.spawn((
66+
Text::new(""),
67+
TextColor(AQUA.into()),
68+
text_font.clone(),
69+
ResponseText,
70+
));
71+
});
72+
parent.spawn(Node::default()).with_children(|parent| {
73+
parent.spawn((Text::new("Ip: "), TextColor(LIME.into()), text_font.clone()));
74+
parent.spawn((
75+
Text::new(""),
76+
TextColor(AQUA.into()),
77+
text_font.clone(),
78+
ResponseIP,
79+
));
80+
});
7481
});
7582
}
7683

7784
fn send_request(
7885
mut ev_request: EventWriter<HttpRequest>,
79-
mut query: Query<&mut Text, With<ResponseText>>,
86+
mut status_query: Query<&mut Text, (With<ResponseText>, Without<ResponseIP>)>,
87+
mut ip_query: Query<&mut Text, (With<ResponseIP>, Without<ResponseText>)>,
8088
) {
81-
let mut text = query.single_mut();
82-
text.sections[1].value = "Requesting".to_string();
83-
text.sections[3].value = "".to_string();
89+
status_query.single_mut().0 = "Requesting ".to_string();
90+
ip_query.single_mut().0 = "".to_string();
8491
let request = HttpClient::new().get("https://api.ipify.org").build();
8592
ev_request.send(request);
8693
}
8794

8895
fn handle_response(
8996
mut ev_resp: EventReader<HttpResponse>,
90-
mut query: Query<&mut Text, With<ResponseText>>,
97+
mut status_query: Query<&mut Text, (With<ResponseText>, Without<ResponseIP>)>,
98+
mut ip_query: Query<&mut Text, (With<ResponseIP>, Without<ResponseText>)>,
9199
) {
92100
for response in ev_resp.read() {
93-
let mut text = query.single_mut();
94101
let ip = response.text().unwrap_or_default();
95-
96-
text.sections[1].value = "Got ".to_string();
97-
text.sections[3].value = ip.to_string();
102+
ip_query.single_mut().0 = ip.to_string();
103+
status_query.single_mut().0 = "Got ".to_string();
98104
}
99105
}
100-
101106
fn handle_error(mut ev_error: EventReader<HttpResponseError>) {
102107
for error in ev_error.read() {
103108
println!("Error retrieving IP: {}", error.err);

0 commit comments

Comments
 (0)