Expand description
Global device-pixel-ratio (DPI) scale factor.
All layout values (margin, padding, min_size, max_size) are stored
in logical (device-independent) units. Layout algorithms call
device_scale once per frame (or per layout pass) and multiply logical
values by the factor to obtain physical pixel values.
§Typical usage
ⓘ
// At startup / when the window moves to a different monitor:
agg_gui::device_scale::set_device_scale(window.scale_factor());
// Inside a layout algorithm:
let physical_margin = child.margin().scale(device_scale());§Thread safety
GUI layout always runs on the main thread. The value is stored in a
thread-local Cell so reads are zero-cost (no atomic, no lock).
On WASM there is only one thread, so this works correctly there too.
Functions§
- device_
scale - Return the current device scale factor (default
1.0). - set_
device_ scale - Set the device scale factor.