Skip to content

Support UI scaling  #195

@ropewalker

Description

@ropewalker

A window created using the following code has correct size in physical pixels, however it doesn't respect UI scaling, so it looks small on devices with scale factor different from 1.0:

use bevy::prelude::*;
use bevy_window::WindowMode;

fn main() {
    App::build()
        .add_resource(WindowDescriptor {
            title: "I am a window!".to_string(),
            width: 800,
            height: 600,
            vsync: true,
            resizable: true,
            ..Default::default()
        })
        .add_default_plugins()
        .run();
}

Changing this line:

.with_inner_size(winit::dpi::PhysicalSize::new(window.width, window.height))
to

.with_inner_size(winit::dpi::LogicalSize::new(window.width, window.height))

seems to help: see the screenshot below — both windows are created on MacBook Pro 13'' (with physical resolution 2560×1600 scaled to 1440×900) by running the code above, but window on the left was created before the change, and window on the right after the change:

UI scaling

I am not sure which behavior is “correct”, but it seems reasonable that it should be at least configurable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions