Skip to content
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

Closed
wants to merge 17 commits into from
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,46 @@ impl From<DVec2> for WindowResolution {
}
}

/// Common screen resolutions.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum Resolution {
/// 640 x 360
R360p,

/// 1280 x 720
R720p,

/// 1920 x 1080
R1080p,

/// 2560 x 1440
R2k,
Copy link

@GunboatDiplomat GunboatDiplomat Jul 7, 2024

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).

}

impl Resolution {
/// Iterates through all [`Resolution`] variants.
pub fn iter() -> impl Iterator<Item = Resolution> {
[
Resolution::R360p,
Resolution::R720p,
Resolution::R1080p,
Resolution::R2k,
]
.into_iter()
}
}

impl From<Resolution> for UVec2 {
fn from(resolution: Resolution) -> Self {
match resolution {
Resolution::R360p => Self::new(640, 360),
Resolution::R720p => Self::new(1280, 720),
Resolution::R1080p => Self::new(1920, 1080),
Resolution::R2k => Self::new(2560, 1440),
}
}
}

/// Defines if and how the [`Cursor`] is grabbed by a [`Window`].
///
/// ## Platform-specific
Expand Down