minimizing/
minimizing.rs

1//! A test to confirm that `bevy` allows minimizing the window
2//! This is run in CI to ensure that this doesn't regress again.
3use bevy::{diagnostic::FrameCount, prelude::*};
4
5fn main() {
6    // TODO: Combine this with `resizing` once multiple_windows is simpler than
7    // it is currently.
8    App::new()
9        .add_plugins(DefaultPlugins.set(WindowPlugin {
10            primary_window: Some(Window {
11                title: "Minimizing".into(),
12                ..default()
13            }),
14            ..default()
15        }))
16        .add_systems(Startup, (setup_3d, setup_2d))
17        .add_systems(Update, minimize_automatically)
18        .run();
19}
20
21fn minimize_automatically(mut window: Single<&mut Window>, frames: Res<FrameCount>) {
22    if frames.0 != 60 {
23        return;
24    }
25
26    window.set_minimized(true);
27}
28
29/// A simple 3d scene, taken from the `3d_scene` example
30fn setup_3d(
31    mut commands: Commands,
32    mut meshes: ResMut<Assets<Mesh>>,
33    mut materials: ResMut<Assets<StandardMaterial>>,
34) {
35    // plane
36    commands.spawn((
37        Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
38        MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
39    ));
40    // cube
41    commands.spawn((
42        Mesh3d(meshes.add(Cuboid::default())),
43        MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
44        Transform::from_xyz(0.0, 0.5, 0.0),
45    ));
46    // light
47    commands.spawn((
48        PointLight {
49            shadows_enabled: true,
50            ..default()
51        },
52        Transform::from_xyz(4.0, 8.0, 4.0),
53    ));
54    // camera
55    commands.spawn((
56        Camera3d::default(),
57        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
58    ));
59}
60
61/// A simple 2d scene, taken from the `rect` example
62fn setup_2d(mut commands: Commands) {
63    commands.spawn((
64        Camera2d,
65        Camera {
66            // render the 2d camera after the 3d camera
67            order: 1,
68            // do not use a clear color
69            clear_color: ClearColorConfig::None,
70            ..default()
71        },
72    ));
73    commands.spawn(Sprite::from_color(
74        Color::srgb(0.25, 0.25, 0.75),
75        Vec2::new(50.0, 50.0),
76    ));
77}