/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include #include namespace facebook::yoga { struct LayoutResults { // This value was chosen based on empirical data: // 98% of analyzed layouts require less than 8 entries. static constexpr int32_t MaxCachedMeasurements = 8; std::array position = {}; std::array margin = {}; std::array border = {}; std::array padding = {}; private: Direction direction_ : bitCount() = Direction::Inherit; bool hadOverflow_ : 1 = false; std::array dimensions_ = {{YGUndefined, YGUndefined}}; std::array measuredDimensions_ = {{YGUndefined, YGUndefined}}; public: uint32_t computedFlexBasisGeneration = 0; FloatOptional computedFlexBasis = {}; // Instead of recomputing the entire layout every single time, we cache some // information to break early when nothing changed uint32_t generationCount = 0; Direction lastOwnerDirection = Direction::Inherit; uint32_t nextCachedMeasurementsIndex = 0; std::array cachedMeasurements = {}; CachedMeasurement cachedLayout{}; Direction direction() const { return direction_; } void setDirection(Direction direction) { direction_ = direction; } bool hadOverflow() const { return hadOverflow_; } void setHadOverflow(bool hadOverflow) { hadOverflow_ = hadOverflow; } float dimension(YGDimension axis) const { return dimensions_[axis]; } void setDimension(YGDimension axis, float dimension) { dimensions_[axis] = dimension; } float measuredDimension(YGDimension axis) const { return measuredDimensions_[axis]; } void setMeasuredDimension(YGDimension axis, float dimension) { measuredDimensions_[axis] = dimension; } bool operator==(LayoutResults layout) const; bool operator!=(LayoutResults layout) const { return !(*this == layout); } }; } // namespace facebook::yoga