2 * Copyright (c) 2014-present, Facebook, Inc.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
10 const YGValue kYGValueUndefined = {0, YGUnitUndefined};
12 const YGValue kYGValueAuto = {0, YGUnitAuto};
14 const std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
25 const std::array<YGValue, 2> kYGDefaultDimensionValuesAutoUnit = {
26 {kYGValueAuto, kYGValueAuto}};
28 const std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
29 {kYGValueUndefined, kYGValueUndefined}};
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()) {}
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);
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();
80 areNonFloatValuesEqual = areNonFloatValuesEqual &&
81 flexGrow.isUndefined() == style.flexGrow.isUndefined();
82 if (areNonFloatValuesEqual && !flexGrow.isUndefined()) {
83 areNonFloatValuesEqual = areNonFloatValuesEqual &&
84 flexGrow.getValue() == style.flexGrow.getValue();
87 areNonFloatValuesEqual = areNonFloatValuesEqual &&
88 flexShrink.isUndefined() == style.flexShrink.isUndefined();
89 if (areNonFloatValuesEqual && !style.flexShrink.isUndefined()) {
90 areNonFloatValuesEqual = areNonFloatValuesEqual &&
91 flexShrink.getValue() == style.flexShrink.getValue();
94 if (!(aspectRatio.isUndefined() && style.aspectRatio.isUndefined())) {
95 areNonFloatValuesEqual = areNonFloatValuesEqual &&
96 aspectRatio.getValue() == style.aspectRatio.getValue();
99 return areNonFloatValuesEqual;
102 bool YGStyle::operator!=(const YGStyle& style) {
103 return !(*this == style);
106 YGStyle::~YGStyle() {}