[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / third-party / yoga / Yoga-internal.h
1 /**
2  * Copyright (c) 2014-present, Facebook, Inc.
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 #include <algorithm>
10 #include <array>
11 #include <cmath>
12 #include <vector>
13 #include "Yoga.h"
14
15 using YGVector = std::vector<YGNodeRef>;
16
17 YG_EXTERN_C_BEGIN
18
19 WIN_EXPORT float YGRoundValueToPixelGrid(const float value,
20                                          const float pointScaleFactor,
21                                          const bool forceCeil,
22                                          const bool forceFloor);
23
24 YG_EXTERN_C_END
25
26 extern const std::array<YGEdge, 4> trailing;
27 extern const std::array<YGEdge, 4> leading;
28 extern bool YGValueEqual(const YGValue a, const YGValue b);
29 extern const YGValue YGValueUndefined;
30 extern const YGValue YGValueAuto;
31 extern const YGValue YGValueZero;
32
33 template <std::size_t size>
34 bool YGValueArrayEqual(
35     const std::array<YGValue, size> val1,
36     const std::array<YGValue, size> val2) {
37   bool areEqual = true;
38   for (uint32_t i = 0; i < size && areEqual; ++i) {
39     areEqual = YGValueEqual(val1[i], val2[i]);
40   }
41   return areEqual;
42 }
43
44 struct YGCachedMeasurement {
45   float availableWidth;
46   float availableHeight;
47   YGMeasureMode widthMeasureMode;
48   YGMeasureMode heightMeasureMode;
49
50   float computedWidth;
51   float computedHeight;
52
53   YGCachedMeasurement()
54       : availableWidth(0),
55         availableHeight(0),
56         widthMeasureMode((YGMeasureMode)-1),
57         heightMeasureMode((YGMeasureMode)-1),
58         computedWidth(-1),
59         computedHeight(-1) {}
60
61   bool operator==(const YGCachedMeasurement& measurement) const {
62     bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
63         heightMeasureMode == measurement.heightMeasureMode;
64
65     if (!YGFloatIsUndefined(availableWidth) ||
66         !YGFloatIsUndefined(measurement.availableWidth)) {
67       isEqual = isEqual && availableWidth == measurement.availableWidth;
68     }
69     if (!YGFloatIsUndefined(availableHeight) ||
70         !YGFloatIsUndefined(measurement.availableHeight)) {
71       isEqual = isEqual && availableHeight == measurement.availableHeight;
72     }
73     if (!YGFloatIsUndefined(computedWidth) ||
74         !YGFloatIsUndefined(measurement.computedWidth)) {
75       isEqual = isEqual && computedWidth == measurement.computedWidth;
76     }
77     if (!YGFloatIsUndefined(computedHeight) ||
78         !YGFloatIsUndefined(measurement.computedHeight)) {
79       isEqual = isEqual && computedHeight == measurement.computedHeight;
80     }
81
82     return isEqual;
83   }
84 };
85
86 // This value was chosen based on empiracle data. Even the most complicated
87 // layouts should not require more than 16 entries to fit within the cache.
88 #define YG_MAX_CACHED_RESULT_COUNT 16
89
90
91 static const float kDefaultFlexGrow = 0.0f;
92 static const float kDefaultFlexShrink = 0.0f;
93 static const float kWebDefaultFlexShrink = 1.0f;
94
95 extern bool YGFloatsEqual(const float a, const float b);
96 extern bool YGValueEqual(const YGValue a, const YGValue b);
97 extern const YGValue* YGComputedEdgeValue(
98     const std::array<YGValue, YGEdgeCount>& edges,
99     const YGEdge edge,
100     const YGValue* const defaultValue);