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

apply window scale to window size when creating it #13967

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,18 @@ impl WindowResolution {
self.scale_factor = scale_factor;
}

/// Set the window's scale factor, and apply it to the currently known physical size.
/// This may get overridden by the backend. This is mostly useful on window creation,
/// so that the window is created with the expected size instead of waiting for a resize
/// event after its creation.
#[inline]
#[doc(hidden)]
pub fn set_scale_factor_and_apply_to_physical_size(&mut self, scale_factor: f32) {
self.scale_factor = scale_factor;
self.physical_width = (self.physical_width as f32 * scale_factor) as u32;
self.physical_height = (self.physical_height as f32 * scale_factor) as u32;
}

/// Set the window's scale factor, this will be used over what the backend decides.
///
/// This can change the logical and physical sizes if the resulting physical
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_winit/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn create_windows<F: QueryFilter + 'static>(

window
.resolution
.set_scale_factor(winit_window.scale_factor() as f32);
.set_scale_factor_and_apply_to_physical_size(winit_window.scale_factor() as f32);

commands.entity(entity).insert(CachedWindow {
window: window.clone(),
Expand Down