Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <stdbool.h> |
11 | | |
12 | | #include <yoga/YGEnums.h> |
13 | | #include <yoga/YGMacros.h> |
14 | | |
15 | | /** |
16 | | * Float value to represent "undefined" in style values. |
17 | | */ |
18 | | #ifdef __cplusplus |
19 | | #include <limits> |
20 | | constexpr float YGUndefined = std::numeric_limits<float>::quiet_NaN(); |
21 | | #else |
22 | | #include <math.h> |
23 | | #define YGUndefined NAN |
24 | | #endif |
25 | | |
26 | | YG_EXTERN_C_BEGIN |
27 | | |
28 | | /** |
29 | | * Structure used to represent a dimension in a style. |
30 | | */ |
31 | | typedef struct YGValue { |
32 | | float value; |
33 | | YGUnit unit; |
34 | | } YGValue; |
35 | | |
36 | | /** |
37 | | * Constant for a dimension of "auto". |
38 | | */ |
39 | | YG_EXPORT extern const YGValue YGValueAuto; |
40 | | |
41 | | /** |
42 | | * Constant for a dimension which is not defined. |
43 | | */ |
44 | | YG_EXPORT extern const YGValue YGValueUndefined; |
45 | | |
46 | | /** |
47 | | * Constant for a dimension that is zero-length. |
48 | | */ |
49 | | YG_EXPORT extern const YGValue YGValueZero; |
50 | | |
51 | | /** |
52 | | * Whether a dimension represented as a float is defined. |
53 | | */ |
54 | | YG_EXPORT bool YGFloatIsUndefined(float value); |
55 | | |
56 | | YG_EXTERN_C_END |
57 | | |
58 | | // Equality operators for comparison of YGValue in C++ |
59 | | #ifdef __cplusplus |
60 | 0 | inline bool operator==(const YGValue& lhs, const YGValue& rhs) { |
61 | 0 | if (lhs.unit != rhs.unit) { |
62 | 0 | return false; |
63 | 0 | } |
64 | 0 |
|
65 | 0 | switch (lhs.unit) { |
66 | 0 | case YGUnitUndefined: |
67 | 0 | case YGUnitAuto: |
68 | 0 | case YGUnitFitContent: |
69 | 0 | case YGUnitMaxContent: |
70 | 0 | case YGUnitStretch: |
71 | 0 | return true; |
72 | 0 | case YGUnitPoint: |
73 | 0 | case YGUnitPercent: |
74 | 0 | return lhs.value == rhs.value; |
75 | 0 | default: |
76 | 0 | return false; |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | 0 | inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { |
81 | 0 | return !(lhs == rhs); |
82 | 0 | } |
83 | | |
84 | 0 | inline YGValue operator-(const YGValue& value) { |
85 | 0 | return {-value.value, value.unit}; |
86 | 0 | } |
87 | | #endif |