Skip to content

Commit

Permalink
Don't 'abuse' 0x0 windows for the example
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Apr 18, 2022
1 parent 6295697 commit 4ae5f9e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .github/example-run/expanding_window.ron

This file was deleted.

5 changes: 5 additions & 0 deletions .github/example-run/minimising.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(
// We have no promised about frame rate.
// TODO: Make this as small as is feasible
exit_after: Some(410)
)
4 changes: 4 additions & 0 deletions .github/example-run/resizing.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(
// Ensures that the full cycle will run
exit_after: Some(410)
)
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,13 @@ name = "window_settings"
path = "examples/window/window_settings.rs"

[[example]]
name = "expanding_window"
path = "examples/window/expanding_window.rs"
name = "resizing"
path = "examples/window/resizing.rs"

[[example]]
name = "minimising"
path = "examples/window/minimising.rs"


# Android
[[example]]
Expand Down
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ Example | File | Description
`scale_factor_override` | [`window/scale_factor_override.rs`](./window/scale_factor_override.rs) | Illustrates how to customize the default window settings
`transparent_window` | [`window/transparent_window.rs`](./window/transparent_window.rs) | Illustrates making the window transparent and hiding the window decoration
`window_settings` | [`window/window_settings.rs`](./window/window_settings.rs) | Demonstrates customizing default window settings
`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
`resizing` | [`window/resizing.rs`](./window/resizing.rs) | Demonstrates changing window size at runtime. Also used to validate that `bevy` can handle arbitrarily small windows
`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

# Platform-Specific Examples

Expand Down
67 changes: 67 additions & 0 deletions examples/window/minimising.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use std::time::Duration;

use bevy::prelude::*;

#[derive(Deref, DerefMut)]
struct MinimiseTimer(Timer);

fn main() {
// TODO: Combine this with `resizing` once multiple_windows is simpler than
// it is currently.
App::new()
.insert_resource(WindowDescriptor {
title: "Minimising".into(),
..Default::default()
})
.insert_resource(MinimiseTimer(Timer::new(Duration::from_secs(2), false)))
.add_plugins(DefaultPlugins)
.add_system(minimise_automatically)
.add_startup_system(setup)
.run();
}

fn minimise_automatically(
mut windows: ResMut<Windows>,
mut timer: ResMut<MinimiseTimer>,
time: Res<Time>,
) {
if timer.tick(time.delta()).just_finished() {
windows.get_primary_mut().unwrap().set_minimized(true);
}
}

/// A simple 3d scene, taken from the `3d_scene` example
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// plane
commands.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
});
// cube
commands.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// light
commands.spawn_bundle(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
// camera
commands.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bevy::{input::system::exit_on_esc_system, prelude::*};

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

Expand All @@ -14,6 +16,7 @@ fn main() {
width: MAX_WIDTH.try_into().unwrap(),
height: MAX_HEIGHT.try_into().unwrap(),
scale_factor_override: Some(1.),
title: "Resizing".into(),
..Default::default()
})
.insert_resource(Dimensions {
Expand Down Expand Up @@ -45,6 +48,7 @@ fn change_window_size(
) {
// Put off rendering for one frame, as currently for a frame where
// resizing happens, nothing is presented.
// TODO: Debug and fix this if feasible
if !*first_complete {
*first_complete = true;
return;
Expand Down

0 comments on commit 4ae5f9e

Please sign in to comment.