2021-02-26 14:24:23 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) Facebook, Inc. and its 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
|
2021-04-20 10:18:06 +08:00
|
|
|
#include "BitUtils.h"
|
2021-02-26 14:24:23 +08:00
|
|
|
#include "YGFloatOptional.h"
|
|
|
|
#include "Yoga-internal.h"
|
|
|
|
|
2021-04-20 10:18:06 +08:00
|
|
|
using namespace facebook::yoga;
|
|
|
|
|
2021-02-26 14:24:23 +08:00
|
|
|
struct YGLayout {
|
|
|
|
std::array<float, 4> position = {};
|
|
|
|
std::array<float, 2> dimensions = {{YGUndefined, YGUndefined}};
|
|
|
|
std::array<float, 4> margin = {};
|
|
|
|
std::array<float, 4> border = {};
|
|
|
|
std::array<float, 4> padding = {};
|
|
|
|
|
|
|
|
private:
|
2021-04-20 10:18:06 +08:00
|
|
|
static constexpr size_t directionOffset = 0;
|
|
|
|
static constexpr size_t didUseLegacyFlagOffset =
|
|
|
|
directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
|
|
|
|
static constexpr size_t doesLegacyStretchFlagAffectsLayoutOffset =
|
|
|
|
didUseLegacyFlagOffset + 1;
|
|
|
|
static constexpr size_t hadOverflowOffset =
|
|
|
|
doesLegacyStretchFlagAffectsLayoutOffset + 1;
|
|
|
|
uint8_t flags = 0;
|
2021-02-26 14:24:23 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
uint32_t computedFlexBasisGeneration = 0;
|
|
|
|
YGFloatOptional computedFlexBasis = {};
|
|
|
|
|
|
|
|
// Instead of recomputing the entire layout every single time, we cache some
|
|
|
|
// information to break early when nothing changed
|
|
|
|
uint32_t generationCount = 0;
|
2021-04-20 10:18:06 +08:00
|
|
|
YGDirection lastOwnerDirection = YGDirectionInherit;
|
2021-02-26 14:24:23 +08:00
|
|
|
|
|
|
|
uint32_t nextCachedMeasurementsIndex = 0;
|
|
|
|
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
|
|
|
|
cachedMeasurements = {};
|
|
|
|
std::array<float, 2> measuredDimensions = {{YGUndefined, YGUndefined}};
|
|
|
|
|
|
|
|
YGCachedMeasurement cachedLayout = YGCachedMeasurement();
|
|
|
|
|
2021-04-20 10:18:06 +08:00
|
|
|
YGDirection direction() const {
|
|
|
|
return facebook::yoga::detail::getEnumData<YGDirection>(
|
|
|
|
flags, directionOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDirection(YGDirection direction) {
|
|
|
|
facebook::yoga::detail::setEnumData<YGDirection>(
|
|
|
|
flags, directionOffset, direction);
|
2021-02-26 14:24:23 +08:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:18:06 +08:00
|
|
|
bool didUseLegacyFlag() const {
|
|
|
|
return facebook::yoga::detail::getBooleanData(
|
|
|
|
flags, didUseLegacyFlagOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDidUseLegacyFlag(bool val) {
|
|
|
|
facebook::yoga::detail::setBooleanData(flags, didUseLegacyFlagOffset, val);
|
2021-02-26 14:24:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool doesLegacyStretchFlagAffectsLayout() const {
|
2021-04-20 10:18:06 +08:00
|
|
|
return facebook::yoga::detail::getBooleanData(
|
|
|
|
flags, doesLegacyStretchFlagAffectsLayoutOffset);
|
2021-02-26 14:24:23 +08:00
|
|
|
}
|
2021-04-20 10:18:06 +08:00
|
|
|
|
|
|
|
void setDoesLegacyStretchFlagAffectsLayout(bool val) {
|
|
|
|
facebook::yoga::detail::setBooleanData(
|
|
|
|
flags, doesLegacyStretchFlagAffectsLayoutOffset, val);
|
2021-02-26 14:24:23 +08:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:18:06 +08:00
|
|
|
bool hadOverflow() const {
|
|
|
|
return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset);
|
|
|
|
}
|
|
|
|
void setHadOverflow(bool hadOverflow) {
|
|
|
|
facebook::yoga::detail::setBooleanData(
|
|
|
|
flags, hadOverflowOffset, hadOverflow);
|
2021-02-26 14:24:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(YGLayout layout) const;
|
|
|
|
bool operator!=(YGLayout layout) const { return !(*this == layout); }
|
|
|
|
};
|