Skip to content

Commit bbb2c90

Browse files
committed
Add an example to test small window sizes
1 parent b3e39d0 commit bbb2c90

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(
2+
exit_after: Some(410)
3+
)

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ path = "examples/window/transparent_window.rs"
615615
name = "window_settings"
616616
path = "examples/window/window_settings.rs"
617617

618+
[[example]]
619+
name = "expanding_window"
620+
path = "examples/window/expanding_window.rs"
621+
618622
# Android
619623
[[example]]
620624
crate-type = ["cdylib"]

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ Example | File | Description
307307
`scale_factor_override` | [`window/scale_factor_override.rs`](./window/scale_factor_override.rs) | Illustrates how to customize the default window settings
308308
`transparent_window` | [`window/transparent_window.rs`](./window/transparent_window.rs) | Illustrates making the window transparent and hiding the window decoration
309309
`window_settings` | [`window/window_settings.rs`](./window/window_settings.rs) | Demonstrates customizing default window settings
310+
`expanding_window` | [`window/expanding_window.rs`](./window/expanding_window.rs) | Demonstrates changing window settings at runtime. Also used to validate that `bevy` can handle arbitrarily small windows
310311

311312
# Platform-Specific Examples
312313

examples/window/expanding_window.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use bevy::prelude::*;
2+
3+
fn main() {
4+
App::new()
5+
.insert_resource(WindowDescriptor {
6+
width: 200.,
7+
height: 200.,
8+
scale_factor_override: Some(1.),
9+
..Default::default()
10+
})
11+
.add_plugins(DefaultPlugins)
12+
.insert_resource(Phase::ContractingY)
13+
.add_system(change_window_size)
14+
.run();
15+
}
16+
17+
enum Phase {
18+
ContractingY,
19+
ContractingX,
20+
ExpandingY,
21+
ExpandingX,
22+
}
23+
24+
use Phase::*;
25+
26+
fn change_window_size(mut windows: ResMut<Windows>, mut phase: ResMut<Phase>) {
27+
let primary = windows.get_primary_mut().unwrap();
28+
let height = primary.height();
29+
let width = primary.width();
30+
match *phase {
31+
Phase::ContractingY => {
32+
if height <= 0.5 {
33+
*phase = ContractingX;
34+
}
35+
primary.set_resolution(width, (height - 4.).max(0.0))
36+
}
37+
Phase::ContractingX => {
38+
if width <= 0.5 {
39+
*phase = ExpandingY;
40+
}
41+
primary.set_resolution((width - 4.).max(0.0), height)
42+
}
43+
Phase::ExpandingY => {
44+
if height >= 200. {
45+
*phase = ExpandingX;
46+
}
47+
primary.set_resolution(width, height + 4.)
48+
}
49+
Phase::ExpandingX => {
50+
if width >= 200. {
51+
*phase = ContractingY;
52+
}
53+
primary.set_resolution(width + 4., height)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)