WindowResolution

WindowResolution

  • physical_width : u32
  • physical_height : u32
  • scale_factor_override : core::option::Option
  • scale_factor : f32

Description

Controls the size of a [Window]

Physical, logical and requested sizes

There are three sizes associated with a window:

  • the physical size, which represents the actual height and width in physical pixels the window occupies on the monitor,
  • the logical size, which represents the size that should be used to scale elements inside the window, measured in logical pixels,
  • the requested size, measured in logical pixels, which is the value submitted to the API when creating the window, or requesting that it be resized.

Scale factor

The reason logical size and physical size are separated and can be different is to account for the cases where:

  • several monitors have different pixel densities,
  • the user has set up a pixel density preference in its operating system,
  • the Bevy App has specified a specific scale factor between both.

The factor between physical size and logical size can be retrieved with [WindowResolution::scale_factor].

For the first two cases, a scale factor is set automatically by the operating system through the window backend. You can get it with [WindowResolution::base_scale_factor].

For the third case, you can override this automatic scale factor with [WindowResolution::set_scale_factor_override].

Requested and obtained sizes

The logical size should be equal to the requested size after creating/resizing, when possible. The reason the requested size and logical size might be different is because the corresponding physical size might exceed limits (either the size limits of the monitor, or limits defined in [WindowResizeConstraints]).

Note: The requested size is not kept in memory, for example requesting a size too big for the screen, making the logical size different from the requested size, and then setting a scale factor that makes the previous requested size within the limits of the screen will not get back that previous requested size.

Functions