Skip to content

Commit 6295697

Browse files
committed
No longer test 0x0 windows as they are unsupported on X11
1 parent c1c191f commit 6295697

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

examples/window/expanding_window.rs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
use bevy::prelude::*;
1+
use bevy::{input::system::exit_on_esc_system, prelude::*};
22

3-
const MAX_WIDTH: f32 = 400.;
4-
const MAX_HEIGHT: f32 = 400.;
3+
const MAX_WIDTH: u16 = 401;
4+
const MAX_HEIGHT: u16 = 401;
5+
6+
struct Dimensions {
7+
width: u16,
8+
height: u16,
9+
}
510

611
fn main() {
712
App::new()
813
.insert_resource(WindowDescriptor {
9-
width: MAX_WIDTH,
10-
height: MAX_HEIGHT,
14+
width: MAX_WIDTH.try_into().unwrap(),
15+
height: MAX_HEIGHT.try_into().unwrap(),
1116
scale_factor_override: Some(1.),
1217
..Default::default()
1318
})
19+
.insert_resource(Dimensions {
20+
width: MAX_WIDTH,
21+
height: MAX_HEIGHT,
22+
})
1423
.add_plugins(DefaultPlugins)
1524
.insert_resource(Phase::ContractingY)
1625
.add_system(change_window_size)
26+
.add_system(sync_dimensions)
27+
.add_system(exit_on_esc_system)
1728
.add_startup_system(setup)
1829
.run();
1930
}
@@ -28,7 +39,7 @@ enum Phase {
2839
use Phase::*;
2940

3041
fn change_window_size(
31-
mut windows: ResMut<Windows>,
42+
mut windows: ResMut<Dimensions>,
3243
mut phase: ResMut<Phase>,
3344
mut first_complete: Local<bool>,
3445
) {
@@ -38,37 +49,49 @@ fn change_window_size(
3849
*first_complete = true;
3950
return;
4051
}
41-
let primary = windows.get_primary_mut().unwrap();
42-
let height = primary.height();
43-
let width = primary.width();
52+
let height = windows.height;
53+
let width = windows.width;
4454
match *phase {
4555
Phase::ContractingY => {
46-
if height <= 0.5 {
56+
if windows.height <= 1 {
4757
*phase = ContractingX;
58+
} else {
59+
windows.height -= 4;
4860
}
49-
primary.set_resolution(width, (height - 4.).max(0.0))
5061
}
5162
Phase::ContractingX => {
52-
if width <= 0.5 {
63+
if width <= 1 {
5364
*phase = ExpandingY;
65+
} else {
66+
windows.width -= 4;
5467
}
55-
primary.set_resolution((width - 4.).max(0.0), height)
5668
}
5769
Phase::ExpandingY => {
5870
if height >= MAX_HEIGHT {
5971
*phase = ExpandingX;
72+
} else {
73+
windows.height += 4;
6074
}
61-
primary.set_resolution(width, height + 4.)
6275
}
6376
Phase::ExpandingX => {
6477
if width >= MAX_WIDTH {
6578
*phase = ContractingY;
79+
} else {
80+
windows.width += 4;
6681
}
67-
primary.set_resolution(width + 4., height)
6882
}
6983
}
7084
}
7185

86+
fn sync_dimensions(dim: Res<Dimensions>, mut windows: ResMut<Windows>) {
87+
if dim.is_changed() {
88+
windows.get_primary_mut().unwrap().set_resolution(
89+
dim.width.try_into().unwrap(),
90+
dim.height.try_into().unwrap(),
91+
);
92+
}
93+
}
94+
7295
/// A simple 3d scene, taken from the `3d_scene` example
7396
fn setup(
7497
mut commands: Commands,

0 commit comments

Comments
 (0)