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

WindowPosition::Centered doesn't work correctly when scale_factor is not 1.0 #5581

Closed
rparrett opened this issue Aug 5, 2022 · 0 comments
Closed
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior

Comments

@rparrett
Copy link
Contributor

rparrett commented Aug 5, 2022

Bevy version

bevy main

Relevant system information

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

Built-in Liquid Retina XDR Display
16-inch (3456 × 2234)

What you did

use bevy::prelude::*;

fn main() {
    App::new()
        .insert_resource(WindowDescriptor {
            position: WindowPosition::Centered(MonitorSelection::Primary),
            ..default()
        })
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(windows: Res<Windows>) {
    info!("{:?}", windows.get_primary());
}

What went wrong

Window was in the bottom right region of the screen, clearly not in the center, but still completely on-screen.

Some(
    Window {
        id: WindowId(00000000-0000-0000-0000-000000000000),
        requested_width: 1280.0,
        requested_height: 720.0,
        physical_width: 2560,
        physical_height: 1442,
        resize_constraints: WindowResizeConstraints {
            min_width: 180.0,
            min_height: 120.0,
            max_width: inf,
            max_height: inf
        },
        position: Some(IVec2(896, 700)),
        scale_factor_override: None,
        backend_scale_factor: 2.0,
        title: "app",
        present_mode: Fifo,
        resizable: true,
        decorations: true,
        cursor_icon: Default,
        cursor_visible: true,
        cursor_locked: false,
        physical_cursor_position: None,
        raw_window_handle: RawWindowHandleWrapper(AppKit(AppKitHandle { ns_window: 0x116f04da0, ns_view: 0x116e498f0 })),
        focused: true,
        mode: Windowed,
        canvas: None,
        fit_canvas_to_parent: false,
        command_queue: []
    }
)

Additional information

PR incoming

Thanks to @Rigidity for reporting via discord.

@rparrett rparrett added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 5, 2022
@rparrett rparrett added A-Windowing Platform-agnostic interface layer to run your app in and removed S-Needs-Triage This issue needs to be labelled labels Aug 5, 2022
@bors bors bot closed this as completed in e874b91 Aug 30, 2022
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective

Fixes bevyengine#5581

## Solution

`Window::scale_factor` already has logic for selecting the overridden or actual scale factor, so use it.

I tested this with the displays I have access to, but more testing would be nice. This seems like a pretty straightforward bug/fix though.

## Changelog

### Fixed

Fixed window centering on high-dpi displays.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Fixes bevyengine#5581

## Solution

`Window::scale_factor` already has logic for selecting the overridden or actual scale factor, so use it.

I tested this with the displays I have access to, but more testing would be nice. This seems like a pretty straightforward bug/fix though.

## Changelog

### Fixed

Fixed window centering on high-dpi displays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant