DALi Version 2.0.53
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / third-party / yoga / YGStyle.cpp
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 #include "YGStyle.h"
9
10 const YGValue kYGValueUndefined = {0, YGUnitUndefined};
11
12 const YGValue kYGValueAuto = {0, YGUnitAuto};
13
14 const std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
15     {kYGValueUndefined,
16      kYGValueUndefined,
17      kYGValueUndefined,
18      kYGValueUndefined,
19      kYGValueUndefined,
20      kYGValueUndefined,
21      kYGValueUndefined,
22      kYGValueUndefined,
23      kYGValueUndefined}};
24
25 const std::array<YGValue, 2> kYGDefaultDimensionValuesAutoUnit = {
26     {kYGValueAuto, kYGValueAuto}};
27
28 const std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
29     {kYGValueUndefined, kYGValueUndefined}};
30
31 YGStyle::YGStyle()
32     : direction(YGDirectionInherit),
33       flexDirection(YGFlexDirectionColumn),
34       justifyContent(YGJustifyFlexStart),
35       alignContent(YGAlignFlexStart),
36       alignItems(YGAlignStretch),
37       alignSelf(YGAlignAuto),
38       positionType(YGPositionTypeRelative),
39       flexWrap(YGWrapNoWrap),
40       overflow(YGOverflowVisible),
41       display(YGDisplayFlex),
42       flex(YGFloatOptional()),
43       flexGrow(YGFloatOptional()),
44       flexShrink(YGFloatOptional()),
45       flexBasis(kYGValueAuto),
46       margin(kYGDefaultEdgeValuesUnit),
47       position(kYGDefaultEdgeValuesUnit),
48       padding(kYGDefaultEdgeValuesUnit),
49       border(kYGDefaultEdgeValuesUnit),
50       dimensions(kYGDefaultDimensionValuesAutoUnit),
51       minDimensions(kYGDefaultDimensionValuesUnit),
52       maxDimensions(kYGDefaultDimensionValuesUnit),
53       aspectRatio(YGFloatOptional()) {}
54
55 // Yoga specific properties, not compatible with flexbox specification
56 bool YGStyle::operator==(const YGStyle& style) {
57   bool areNonFloatValuesEqual = direction == style.direction &&
58       flexDirection == style.flexDirection &&
59       justifyContent == style.justifyContent &&
60       alignContent == style.alignContent && alignItems == style.alignItems &&
61       alignSelf == style.alignSelf && positionType == style.positionType &&
62       flexWrap == style.flexWrap && overflow == style.overflow &&
63       display == style.display && YGValueEqual(flexBasis, style.flexBasis) &&
64       YGValueArrayEqual(margin, style.margin) &&
65       YGValueArrayEqual(position, style.position) &&
66       YGValueArrayEqual(padding, style.padding) &&
67       YGValueArrayEqual(border, style.border) &&
68       YGValueArrayEqual(dimensions, style.dimensions) &&
69       YGValueArrayEqual(minDimensions, style.minDimensions) &&
70       YGValueArrayEqual(maxDimensions, style.maxDimensions);
71
72   areNonFloatValuesEqual =
73       areNonFloatValuesEqual && flex.isUndefined() == style.flex.isUndefined();
74   if (areNonFloatValuesEqual && !flex.isUndefined() &&
75       !style.flex.isUndefined()) {
76     areNonFloatValuesEqual =
77         areNonFloatValuesEqual && flex.getValue() == style.flex.getValue();
78   }
79
80   areNonFloatValuesEqual = areNonFloatValuesEqual &&
81       flexGrow.isUndefined() == style.flexGrow.isUndefined();
82   if (areNonFloatValuesEqual && !flexGrow.isUndefined()) {
83     areNonFloatValuesEqual = areNonFloatValuesEqual &&
84         flexGrow.getValue() == style.flexGrow.getValue();
85   }
86
87   areNonFloatValuesEqual = areNonFloatValuesEqual &&
88       flexShrink.isUndefined() == style.flexShrink.isUndefined();
89   if (areNonFloatValuesEqual && !style.flexShrink.isUndefined()) {
90     areNonFloatValuesEqual = areNonFloatValuesEqual &&
91         flexShrink.getValue() == style.flexShrink.getValue();
92   }
93
94   if (!(aspectRatio.isUndefined() && style.aspectRatio.isUndefined())) {
95     areNonFloatValuesEqual = areNonFloatValuesEqual &&
96         aspectRatio.getValue() == style.aspectRatio.getValue();
97   }
98
99   return areNonFloatValuesEqual;
100 }
101
102 bool YGStyle::operator!=(const YGStyle& style) {
103   return !(*this == style);
104 }
105
106 YGStyle::~YGStyle() {}