YGStyle.cpp 3.8 KB

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