Skip to content

Commit 4ae5f9e

Browse files
committed
Don't 'abuse' 0x0 windows for the example
1 parent 6295697 commit 4ae5f9e

File tree

7 files changed

+89
-6
lines changed

7 files changed

+89
-6
lines changed

.github/example-run/expanding_window.ron

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/example-run/minimising.ron

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(
2+
// We have no promised about frame rate.
3+
// TODO: Make this as small as is feasible
4+
exit_after: Some(410)
5+
)

.github/example-run/resizing.ron

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(
2+
// Ensures that the full cycle will run
3+
exit_after: Some(410)
4+
)

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,13 @@ name = "window_settings"
616616
path = "examples/window/window_settings.rs"
617617

618618
[[example]]
619-
name = "expanding_window"
620-
path = "examples/window/expanding_window.rs"
619+
name = "resizing"
620+
path = "examples/window/resizing.rs"
621+
622+
[[example]]
623+
name = "minimising"
624+
path = "examples/window/minimising.rs"
625+
621626

622627
# Android
623628
[[example]]

examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ 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
310+
`resizing` | [`window/resizing.rs`](./window/resizing.rs) | Demonstrates changing window size at runtime. Also used to validate that `bevy` can handle arbitrarily small windows
311+
`minimising` | [`window/minimising.rs`](./window/minimising.rs) | Demonstrates minimising a window from within your game. Also used to validate that `bevy` can handle minimised windows
311312

312313
# Platform-Specific Examples
313314

examples/window/minimising.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use std::time::Duration;
2+
3+
use bevy::prelude::*;
4+
5+
#[derive(Deref, DerefMut)]
6+
struct MinimiseTimer(Timer);
7+
8+
fn main() {
9+
// TODO: Combine this with `resizing` once multiple_windows is simpler than
10+
// it is currently.
11+
App::new()
12+
.insert_resource(WindowDescriptor {
13+
title: "Minimising".into(),
14+
..Default::default()
15+
})
16+
.insert_resource(MinimiseTimer(Timer::new(Duration::from_secs(2), false)))
17+
.add_plugins(DefaultPlugins)
18+
.add_system(minimise_automatically)
19+
.add_startup_system(setup)
20+
.run();
21+
}
22+
23+
fn minimise_automatically(
24+
mut windows: ResMut<Windows>,
25+
mut timer: ResMut<MinimiseTimer>,
26+
time: Res<Time>,
27+
) {
28+
if timer.tick(time.delta()).just_finished() {
29+
windows.get_primary_mut().unwrap().set_minimized(true);
30+
}
31+
}
32+
33+
/// A simple 3d scene, taken from the `3d_scene` example
34+
fn setup(
35+
mut commands: Commands,
36+
mut meshes: ResMut<Assets<Mesh>>,
37+
mut materials: ResMut<Assets<StandardMaterial>>,
38+
) {
39+
// plane
40+
commands.spawn_bundle(PbrBundle {
41+
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
42+
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
43+
..default()
44+
});
45+
// cube
46+
commands.spawn_bundle(PbrBundle {
47+
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
48+
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
49+
transform: Transform::from_xyz(0.0, 0.5, 0.0),
50+
..default()
51+
});
52+
// light
53+
commands.spawn_bundle(PointLightBundle {
54+
point_light: PointLight {
55+
intensity: 1500.0,
56+
shadows_enabled: true,
57+
..default()
58+
},
59+
transform: Transform::from_xyz(4.0, 8.0, 4.0),
60+
..default()
61+
});
62+
// camera
63+
commands.spawn_bundle(PerspectiveCameraBundle {
64+
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
65+
..default()
66+
});
67+
}

examples/window/expanding_window.rs renamed to examples/window/resizing.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use bevy::{input::system::exit_on_esc_system, prelude::*};
22

3+
// The smallest size reached is 1x1, as X11 doesn't support windows with a 0 dimension
4+
// TODO: Add a test for platforms other than X11 for 0x0, despite those currently unsupported on CI.
35
const MAX_WIDTH: u16 = 401;
46
const MAX_HEIGHT: u16 = 401;
57

@@ -14,6 +16,7 @@ fn main() {
1416
width: MAX_WIDTH.try_into().unwrap(),
1517
height: MAX_HEIGHT.try_into().unwrap(),
1618
scale_factor_override: Some(1.),
19+
title: "Resizing".into(),
1720
..Default::default()
1821
})
1922
.insert_resource(Dimensions {
@@ -45,6 +48,7 @@ fn change_window_size(
4548
) {
4649
// Put off rendering for one frame, as currently for a frame where
4750
// resizing happens, nothing is presented.
51+
// TODO: Debug and fix this if feasible
4852
if !*first_complete {
4953
*first_complete = true;
5054
return;

0 commit comments

Comments
 (0)