-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposes Common Window Resolutions as an Enum. #14158
Changes from all commits
e08c878
38f080f
76ced3f
c8555a5
8842456
bad94ba
f8b8dfb
884ed08
8deccf6
a450128
a6893e9
c77a640
44c057f
6b2871a
fa8e089
7fb37ee
dceeff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//! Illustrates how to change window settings and shows how to affect | ||
//! the mouse pointer in various ways. | ||
|
||
use bevy::window::{CommonScreenResolution, WindowResolution}; | ||
use bevy::{ | ||
core::FrameCount, | ||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, | ||
|
@@ -15,7 +16,7 @@ fn main() { | |
primary_window: Some(Window { | ||
title: "I am a window!".into(), | ||
name: Some("bevy.app".into()), | ||
resolution: (500., 300.).into(), | ||
resolution: CommonScreenResolution::R360p.into(), | ||
present_mode: PresentMode::AutoVsync, | ||
// Tells wasm to resize the window according to the available canvas | ||
fit_canvas_to_parent: true, | ||
|
@@ -45,6 +46,7 @@ fn main() { | |
toggle_cursor, | ||
toggle_vsync, | ||
toggle_window_controls, | ||
toggle_resolutions, | ||
cycle_cursor_icon, | ||
switch_level, | ||
make_visible, | ||
|
@@ -124,6 +126,30 @@ fn toggle_window_controls(input: Res<ButtonInput<KeyCode>>, mut windows: Query<& | |
} | ||
} | ||
|
||
fn toggle_resolutions(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) { | ||
if input.just_pressed(KeyCode::KeyR) { | ||
let mut window = windows.single_mut(); | ||
let current_resolution = CommonScreenResolution::iter() | ||
.find(|&r| WindowResolution::from(r) == window.resolution); | ||
window.resolution = if current_resolution.is_none() { | ||
CommonScreenResolution::R360p.into() | ||
} else { | ||
let resolutions = CommonScreenResolution::iter() | ||
.map(std::convert::Into::into) | ||
.collect::<Vec<CommonScreenResolution>>(); | ||
let current_resolution_index = CommonScreenResolution::iter() | ||
.position(|r| r == current_resolution.unwrap()) | ||
.unwrap(); | ||
|
||
if current_resolution_index + 1 >= resolutions.len() { | ||
resolutions[0].into() | ||
} else { | ||
resolutions[current_resolution_index + 1].into() | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+129
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be more idiomatic if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
|
||
/// This system will then change the title during execution | ||
fn change_title(mut windows: Query<&mut Window>, time: Res<Time>) { | ||
let mut window = windows.single_mut(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling QHD resolution 2K is a misnomer. 2K is closer to 1080p (FullHD) than 2.5k (QHD).