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 1 commit
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
32 changes: 32 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ impl Default for WindowResolution {
scale_factor: 1.0,
}
}

}

impl WindowResolution {
Expand Down Expand Up @@ -869,6 +870,37 @@ impl From<DVec2> for WindowResolution {
}
}

/// Creates and defines a Resolution Enum to expose common resolutions.
Sapein marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum Resolution{
R360p,
R720p,
R1080p,
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 {
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
Loading