bevyengine / bevyengine/bevy

Window centering does not respect scale factor override

Open
#9,606 2 comments 1 reaction 0 assignees View on GitHub
A-Windowing C-Bug D-Trivial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.11.2

## \[Optional\] Relevant system information

- macOS 13.5
- Apple M1 Max (Metal)

```ignore
`AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }`
```

## What you did

1. Create a basic Bevy application with `DefaultPlugins`
2. Override the `primary_window` to 640x360 in the `WindowPlugin` initialization
3. Add `Startup` system for `setup_resolution` that adjusts `window.resolution.set_scale_factor_override`
4. Call `window.position.center(MonitorSelection::Current)` to center the window
5. Observe incorrect centering using `scale_factor` instead of override

## What went wrong

The window should be centered using the new `scale_factor_override` instead of the current `scale_factor` from the OS.

Ex:

```rust
pub fn setup_resolution(mut windows: Query<&mut Window>) {
let mut window = windows.single_mut();

window.resolution.set_scale_factor_override(Some(3.0));
window.position.center(MonitorSelection::Current);

info!("Window created: {:?}", window.resolution);
}
```

```ignore
`Window created: WindowResolution { physical_width: 1920, physical_height: 1080, scale_factor_override: Some(3.0), scale_factor: 2.0 }`
```

## Additional information

Only tested on macOS currently, not sure if works properly on Windows due to how scale factor works.

I encountered this by working on a pixel-art game with a reference resolution of 640x360 and want to apply a scale factor to retain the sharpness via integer scaling (1x, 2x, 3x, 4x, etc). I don't know if this the correct way, but it did expose this bug.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the Window position.center(MonitorSelection::Current) path and how it reads scale_factor versus scale_factor_override. Reproduce the macOS example with a 640x360 window and an override of 3.0; done means centering uses the override while preserving correct behavior for platforms and windows without one.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.