Expand description
Sizes, points and rectangles, in the two coordinate spaces a window has.
§Physical and logical are different types on purpose
Every windowing bug that outlives a release is a scale-factor bug, and every scale-factor bug is a physical value used where a logical one was meant (or the reverse). So the two are separate types and the only way between them is an explicit conversion that takes the scale factor:
- Physical (
PhysicalSize,PhysicalPoint,PhysicalRect) — device pixels. This is what a swapchain is sized in, what a viewport is sized in, and what a pointer position is reported in. Never guess it. - Logical (
LogicalSize,LogicalPoint) — scale-independent units. This is what a request is expressed in (“open a 1280×720 window”), what min/max constraints are expressed in, and what the UI lays out in. It isf64rather than integer because fractional scaling (Wayland’sfractional-scale-v1reports scale in 1/120ths) makesphysical / scalenon-integral in general.
The engine’s rule: events report physical, requests carry logical. A window asks for a size in a unit the user recognizes; the renderer allocates in the unit the GPU recognizes; the shell is the only thing that converts.
§Rounding
LogicalSize::to_physical rounds to nearest and clamps to at least 1×1.
Zero-sized swapchains are invalid in Vulkan, and a minimized window on Win32
genuinely reports 0×0 — so the clamp is not paranoia, it is the difference
between “the window is minimized” and a validation error.
Structs§
- Aspect
Ratio - A width-to-height ratio, exact.
- Logical
Point - A point in scale-independent units, relative to a window’s top-left corner.
- Logical
Rect - An axis-aligned rectangle in scale-independent units, relative to a window’s top-left corner.
- Logical
Size - A size in scale-independent units.
- Physical
Point - A point in device pixels, relative to a window’s top-left corner.
- Physical
Rect - An axis-aligned rectangle in device pixels.
- Physical
Size - A size in device pixels.