18#include "AUI/Util/Assert.h"
89 float convertValueToMyUnit(
const AMetric& anotherMetric) {
90 return fromPxToMetric(anotherMetric.getValuePx(), mUnit);
110 template<
typename T,
typename std::enable_if_t<std::is_
integral_v<T>,
bool> = 0>
115 "please use _px, _dp or _pt literal for AMetric initialisation. only zero allowed to "
116 "initialise AMetric without literal");
119 constexpr AMetric(
float value, Unit unit): mValue(value), mUnit(unit) {
125 [[nodiscard]]
float getRawValue()
const
130 [[nodiscard]] Unit getUnit()
const
135 [[nodiscard]]
float getValuePx()
const;
136 [[nodiscard]]
float getValueDp()
const;
138 static float fromPxToMetric(
float value, Unit unit);
140 operator float()
const {
145 return {-mValue, mUnit};
150 mValue += rhs.mValue;
156 mValue -= rhs.mValue;
162 mValue *= rhs.mValue;
168 mValue /= rhs.mValue;
200 AMetric& operator*=(
float rhs)
noexcept {
205 AMetric& operator/=(
float rhs)
noexcept {
210 AMetric operator*(
float rhs)
const noexcept {
216 AMetric operator/(
float rhs)
const noexcept {
222 bool operator==(
const AMetric& rhs)
const {
223 return std::tie(mValue, mUnit) == std::tie(rhs.mValue, rhs.mUnit);
226 bool operator!=(
const AMetric& rhs)
const {
227 return !(rhs == *
this);
232constexpr inline AMetric operator""_px(
unsigned long long v)
234 return AMetric(
static_cast<float>(
static_cast<long long>(v)), AMetric::T_PX);
236constexpr inline AMetric operator""_dp(
unsigned long long v)
238 return AMetric(
static_cast<float>(
static_cast<long long>(v)), AMetric::T_DP);
240constexpr inline AMetric operator""_pt(
unsigned long long v)
242 return AMetric(
static_cast<float>(
static_cast<long long>(v)), AMetric::T_PT);
245inline std::ostream& operator<<(std::ostream& o,
const AMetric& value) {
246 o << value.getRawValue();
247 switch (value.getUnit()) {
Stores dimensions in scalable units (dp, pt, etc...).
Definition: AMetric.h:75
constexpr AMetric(T value)
Constructor for AMetric a; a = 0 without unit specifier. Can be used only for zero initialization (se...
Definition: AMetric.h:111
Represents a Unicode character string.
Definition: AString.h:37
#define AUI_ASSERT(condition)
Asserts that the passed condition evaluates to true.
Definition: Assert.h:55
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition: Assert.h:74