Yoga-internal.h 3.1 KB

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