YGLayout.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  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 "BitUtils.h"
  9. #include "YGFloatOptional.h"
  10. #include "Yoga-internal.h"
  11. using namespace facebook::yoga;
  12. struct YGLayout {
  13. std::array<float, 4> position = {};
  14. std::array<float, 2> dimensions = {{YGUndefined, YGUndefined}};
  15. std::array<float, 4> margin = {};
  16. std::array<float, 4> border = {};
  17. std::array<float, 4> padding = {};
  18. private:
  19. static constexpr size_t directionOffset = 0;
  20. static constexpr size_t didUseLegacyFlagOffset =
  21. directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
  22. static constexpr size_t doesLegacyStretchFlagAffectsLayoutOffset =
  23. didUseLegacyFlagOffset + 1;
  24. static constexpr size_t hadOverflowOffset =
  25. doesLegacyStretchFlagAffectsLayoutOffset + 1;
  26. uint8_t flags = 0;
  27. public:
  28. uint32_t computedFlexBasisGeneration = 0;
  29. YGFloatOptional computedFlexBasis = {};
  30. // Instead of recomputing the entire layout every single time, we cache some
  31. // information to break early when nothing changed
  32. uint32_t generationCount = 0;
  33. YGDirection lastOwnerDirection = (YGDirection) -1;
  34. uint32_t nextCachedMeasurementsIndex = 0;
  35. std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
  36. cachedMeasurements = {};
  37. std::array<float, 2> measuredDimensions = {{YGUndefined, YGUndefined}};
  38. YGCachedMeasurement cachedLayout = YGCachedMeasurement();
  39. YGDirection direction() const {
  40. return facebook::yoga::detail::getEnumData<YGDirection>(
  41. flags, directionOffset);
  42. }
  43. void setDirection(YGDirection direction) {
  44. facebook::yoga::detail::setEnumData<YGDirection>(
  45. flags, directionOffset, direction);
  46. }
  47. bool didUseLegacyFlag() const {
  48. return facebook::yoga::detail::getBooleanData(
  49. flags, didUseLegacyFlagOffset);
  50. }
  51. void setDidUseLegacyFlag(bool val) {
  52. facebook::yoga::detail::setBooleanData(flags, didUseLegacyFlagOffset, val);
  53. }
  54. bool doesLegacyStretchFlagAffectsLayout() const {
  55. return facebook::yoga::detail::getBooleanData(
  56. flags, doesLegacyStretchFlagAffectsLayoutOffset);
  57. }
  58. void setDoesLegacyStretchFlagAffectsLayout(bool val) {
  59. facebook::yoga::detail::setBooleanData(
  60. flags, doesLegacyStretchFlagAffectsLayoutOffset, val);
  61. }
  62. bool hadOverflow() const {
  63. return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset);
  64. }
  65. void setHadOverflow(bool hadOverflow) {
  66. facebook::yoga::detail::setBooleanData(
  67. flags, hadOverflowOffset, hadOverflow);
  68. }
  69. bool operator==(YGLayout layout) const;
  70. bool operator!=(YGLayout layout) const { return !(*this == layout); }
  71. };