Skip to content

AMetric#

Stores dimensions in scalable units (dp, pt, etc...).

Header:#include <AUI/Util/AMetric.h>
CMake:aui_link(my_target PUBLIC aui::views)

Detailed Description#

It's highly recommended to use only Density-independent Pixel unit (_dp) to make your application correctly handle systems with high DPI. In AUI, all units are density independent except _px. The only purpose of the _px unit is to define lines of exact one or two pixels wide.

To handle high-density displays in AUI properly, business logic operates on AMetric (logical pixels) level only. AMetric values are translated to physical pixels on layout-managers and AView level.

Initialization#

Recommended way is to use operator literal format:

AMetric a = 5_dp // -> a = 5 dimension-independent units (= pixels on 100% scaling)

Common usage:

AMetric a = 5_dp;
a.getValuePx() // 5 on 100% scale, 6 on 125% scale, etc

AMetric can be also initialized via value and unit:

AMetric a(5, T_DP);

AMetric can be also initialized with zero without unit specified (in this case, AMetric::getUnit will return T_PX):

AMetric zero1 = 0; // zero pixels
AMetric zero2 = {}; // also zero pixels

However, if you try to specify nonzero integer without unit, it will produce a runtime error:

AMetric a = 5; // runtime error

Supported units#

Currently supported units:

Unit Enum Literal Value
Density-independent Pixels T_DP _dp px * scale_factor
Typography point T_PT _pt px * scale_factor * 4 / 3
Pixels T_PX _px px

It's highly recommended to use only Density-independent Pixel unit (_dp). DP guarantees that your application will correctly handle systems with hidpi screens.

Public Types#

Unit#


enum AMetric::Unit

Constant Description
Unit::T_UNKNOWN
Unit::T_PX
Unit::T_DP
Unit::T_PT

Public Methods#

AMetric#


constexpr AMetric::AMetric(T value)

Constructor for AMetric a; a = 0 without unit specifier. Can be used only for zero initialization (see example)

AMetric a = 0; // ok<br />
AMetric b = 5_dp; // ok<br />
AMetric c = 5; // produces error<br />

Arguments
value
should be zero