Skip to content

Commit

Permalink
No longer test 0x0 windows as they are unsupported on X11
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Apr 18, 2022
1 parent c1c191f commit 6295697
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions examples/window/expanding_window.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
use bevy::prelude::*;
use bevy::{input::system::exit_on_esc_system, prelude::*};

const MAX_WIDTH: f32 = 400.;
const MAX_HEIGHT: f32 = 400.;
const MAX_WIDTH: u16 = 401;
const MAX_HEIGHT: u16 = 401;

struct Dimensions {
width: u16,
height: u16,
}

fn main() {
App::new()
.insert_resource(WindowDescriptor {
width: MAX_WIDTH,
height: MAX_HEIGHT,
width: MAX_WIDTH.try_into().unwrap(),
height: MAX_HEIGHT.try_into().unwrap(),
scale_factor_override: Some(1.),
..Default::default()
})
.insert_resource(Dimensions {
width: MAX_WIDTH,
height: MAX_HEIGHT,
})
.add_plugins(DefaultPlugins)
.insert_resource(Phase::ContractingY)
.add_system(change_window_size)
.add_system(sync_dimensions)
.add_system(exit_on_esc_system)
.add_startup_system(setup)
.run();
}
Expand All @@ -28,7 +39,7 @@ enum Phase {
use Phase::*;

fn change_window_size(
mut windows: ResMut<Windows>,
mut windows: ResMut<Dimensions>,
mut phase: ResMut<Phase>,
mut first_complete: Local<bool>,
) {
Expand All @@ -38,37 +49,49 @@ fn change_window_size(
*first_complete = true;
return;
}
let primary = windows.get_primary_mut().unwrap();
let height = primary.height();
let width = primary.width();
let height = windows.height;
let width = windows.width;
match *phase {
Phase::ContractingY => {
if height <= 0.5 {
if windows.height <= 1 {
*phase = ContractingX;
} else {
windows.height -= 4;
}
primary.set_resolution(width, (height - 4.).max(0.0))
}
Phase::ContractingX => {
if width <= 0.5 {
if width <= 1 {
*phase = ExpandingY;
} else {
windows.width -= 4;
}
primary.set_resolution((width - 4.).max(0.0), height)
}
Phase::ExpandingY => {
if height >= MAX_HEIGHT {
*phase = ExpandingX;
} else {
windows.height += 4;
}
primary.set_resolution(width, height + 4.)
}
Phase::ExpandingX => {
if width >= MAX_WIDTH {
*phase = ContractingY;
} else {
windows.width += 4;
}
primary.set_resolution(width + 4., height)
}
}
}

fn sync_dimensions(dim: Res<Dimensions>, mut windows: ResMut<Windows>) {
if dim.is_changed() {
windows.get_primary_mut().unwrap().set_resolution(
dim.width.try_into().unwrap(),
dim.height.try_into().unwrap(),
);
}
}

/// A simple 3d scene, taken from the `3d_scene` example
fn setup(
mut commands: Commands,
Expand Down

0 comments on commit 6295697

Please sign in to comment.