AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AMetric Class Reference

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

Detailed Description

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

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.

Initialization

Recommended way is to use operator literal format:

AMetric a = 5_dp // -> a = 5 dimension-independent units (= pixels on 100% scaling)
Stores dimensions in scalable units (dp, pt, etc...).
Definition: AMetric.h:75

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

{cpp}

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
Note
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

enum  Unit { T_UNKNOWN , T_PX , T_DP , T_PT }
 

Public Member Functions

template<typename T , typename std::enable_if_t< std::is_integral_v< T >, bool > = 0>
constexpr AMetric (T value)
 Constructor for AMetric a; a = 0 without unit specifier. Can be used only for zero initialization (see example) More...
 
constexpr AMetric (float value, Unit unit)
 
 AMetric (const AString &text)
 
float getRawValue () const
 
Unit getUnit () const
 
float getValuePx () const
 
float getValueDp () const
 
 operator float () const
 
AMetric operator- () const
 
AMetricoperator+= (AMetric rhs) noexcept
 
AMetricoperator-= (AMetric rhs) noexcept
 
AMetricoperator*= (AMetric rhs) noexcept
 
AMetricoperator/= (AMetric rhs) noexcept
 
AMetric operator+ (AMetric rhs) const noexcept
 
AMetric operator- (AMetric rhs) const noexcept
 
AMetric operator* (AMetric rhs) const noexcept
 
AMetric operator/ (AMetric rhs) const noexcept
 
AMetricoperator*= (float rhs) noexcept
 
AMetricoperator/= (float rhs) noexcept
 
AMetric operator* (float rhs) const noexcept
 
AMetric operator/ (float rhs) const noexcept
 
bool operator== (const AMetric &rhs) const
 
bool operator!= (const AMetric &rhs) const
 

Static Public Member Functions

static float fromPxToMetric (float value, Unit unit)
 

Constructor & Destructor Documentation

◆ AMetric()

template<typename T , typename std::enable_if_t< std::is_integral_v< T >, bool > = 0>
constexpr AMetric::AMetric ( value)
inlineconstexpr

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

<code>
AMetric a = 0; // ok<br />
AMetric b = 5_dp; // ok<br />
AMetric c = 5; // produces error<br />
</code>
Template Parameters
Tinteger
Parameters
valueshould be zero

#include <AUI/Util/AMetric.h>


The documentation for this class was generated from the following files: