| 1 | /* |
|---|---|
| 2 | * Copyright (C) 2016 The Qt Company Ltd. |
| 3 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 4 | * |
| 5 | * SPDX-License-Identifier: MIT |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <yoga/YGEnums.h> |
| 11 | #include <yoga/YGMacros.h> |
| 12 | |
| 13 | QT_YOGA_NAMESPACE_BEGIN |
| 14 | |
| 15 | YG_EXTERN_C_BEGIN |
| 16 | |
| 17 | typedef struct YGValue { |
| 18 | float value; |
| 19 | YGUnit unit; |
| 20 | } YGValue; |
| 21 | |
| 22 | YOGA_EXPORT extern const YGValue YGValueAuto; |
| 23 | YOGA_EXPORT extern const YGValue YGValueUndefined; |
| 24 | YOGA_EXPORT extern const YGValue YGValueZero; |
| 25 | |
| 26 | YG_EXTERN_C_END |
| 27 | |
| 28 | QT_YOGA_NAMESPACE_END |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | #include <limits> |
| 32 | QT_YOGA_NAMESPACE_BEGIN |
| 33 | constexpr float YGUndefined = std::numeric_limits<float>::quiet_NaN(); |
| 34 | #else |
| 35 | #include <math.h> |
| 36 | QT_YOGA_NAMESPACE_BEGIN |
| 37 | #define YGUndefined NAN |
| 38 | #endif |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | inline bool operator==(const YGValue& lhs, const YGValue& rhs) { |
| 42 | if (lhs.unit != rhs.unit) { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | switch (lhs.unit) { |
| 47 | case YGUnitUndefined: |
| 48 | case YGUnitAuto: |
| 49 | return true; |
| 50 | case YGUnitPoint: |
| 51 | case YGUnitPercent: |
| 52 | return lhs.value == rhs.value; |
| 53 | } |
| 54 | |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { |
| 59 | return !(lhs == rhs); |
| 60 | } |
| 61 | |
| 62 | inline YGValue operator-(const YGValue& value) { |
| 63 | return {.value: -value.value, .unit: value.unit}; |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | QT_YOGA_NAMESPACE_END |
| 68 |
