Encapsulate arrays of YGValue
within YGStyle
Summary: @public Enforce more encapsulation of arrays of `YGValue` in `YGSty;e`. This will allow us to use `CompactValue` in `YGStyle` while (mostly) retaining API compatibility. Reviewed By: SidharthGuglani Differential Revision: D13452042 fbshipit-source-id: 382b1c7245c4bea4280126ab1413e7e931b62eaa
This commit is contained in:
committed by
Facebook Github Bot
parent
8bc89651d6
commit
3df41aefdb
@@ -15,39 +15,35 @@ bool YGStyle::operator==(const YGStyle& style) {
|
|||||||
alignSelf == style.alignSelf && positionType == style.positionType &&
|
alignSelf == style.alignSelf && positionType == style.positionType &&
|
||||||
flexWrap == style.flexWrap && overflow == style.overflow &&
|
flexWrap == style.flexWrap && overflow == style.overflow &&
|
||||||
display == style.display && YGValueEqual(flexBasis, style.flexBasis) &&
|
display == style.display && YGValueEqual(flexBasis, style.flexBasis) &&
|
||||||
YGValueArrayEqual(margin, style.margin) &&
|
margin == style.margin && position == style.position &&
|
||||||
YGValueArrayEqual(position, style.position) &&
|
padding == style.padding && border == style.border &&
|
||||||
YGValueArrayEqual(padding, style.padding) &&
|
dimensions == style.dimensions && minDimensions == style.minDimensions &&
|
||||||
YGValueArrayEqual(border, style.border) &&
|
maxDimensions == style.maxDimensions;
|
||||||
YGValueArrayEqual(dimensions, style.dimensions) &&
|
|
||||||
YGValueArrayEqual(minDimensions, style.minDimensions) &&
|
|
||||||
YGValueArrayEqual(maxDimensions, style.maxDimensions);
|
|
||||||
|
|
||||||
areNonFloatValuesEqual =
|
areNonFloatValuesEqual =
|
||||||
areNonFloatValuesEqual && flex.isUndefined() == style.flex.isUndefined();
|
areNonFloatValuesEqual && flex.isUndefined() == style.flex.isUndefined();
|
||||||
if (areNonFloatValuesEqual && !flex.isUndefined() &&
|
if (areNonFloatValuesEqual && !flex.isUndefined() &&
|
||||||
!style.flex.isUndefined()) {
|
!style.flex.isUndefined()) {
|
||||||
areNonFloatValuesEqual =
|
areNonFloatValuesEqual = areNonFloatValuesEqual && flex == style.flex;
|
||||||
areNonFloatValuesEqual && flex == style.flex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||||
flexGrow.isUndefined() == style.flexGrow.isUndefined();
|
flexGrow.isUndefined() == style.flexGrow.isUndefined();
|
||||||
if (areNonFloatValuesEqual && !flexGrow.isUndefined()) {
|
if (areNonFloatValuesEqual && !flexGrow.isUndefined()) {
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
areNonFloatValuesEqual =
|
||||||
flexGrow == style.flexGrow;
|
areNonFloatValuesEqual && flexGrow == style.flexGrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||||
flexShrink.isUndefined() == style.flexShrink.isUndefined();
|
flexShrink.isUndefined() == style.flexShrink.isUndefined();
|
||||||
if (areNonFloatValuesEqual && !style.flexShrink.isUndefined()) {
|
if (areNonFloatValuesEqual && !style.flexShrink.isUndefined()) {
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
areNonFloatValuesEqual =
|
||||||
flexShrink == style.flexShrink;
|
areNonFloatValuesEqual && flexShrink == style.flexShrink;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(aspectRatio.isUndefined() && style.aspectRatio.isUndefined())) {
|
if (!(aspectRatio.isUndefined() && style.aspectRatio.isUndefined())) {
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
areNonFloatValuesEqual =
|
||||||
aspectRatio == style.aspectRatio;
|
areNonFloatValuesEqual && aspectRatio == style.aspectRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
return areNonFloatValuesEqual;
|
return areNonFloatValuesEqual;
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <initializer_list>
|
||||||
#include "YGFloatOptional.h"
|
#include "YGFloatOptional.h"
|
||||||
#include "Yoga-internal.h"
|
#include "Yoga-internal.h"
|
||||||
#include "Yoga.h"
|
#include "Yoga.h"
|
||||||
@@ -13,22 +16,9 @@ constexpr YGValue kYGValueUndefined = {0, YGUnitUndefined};
|
|||||||
|
|
||||||
constexpr YGValue kYGValueAuto = {0, YGUnitAuto};
|
constexpr YGValue kYGValueAuto = {0, YGUnitAuto};
|
||||||
|
|
||||||
constexpr std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
|
|
||||||
{kYGValueUndefined,
|
|
||||||
kYGValueUndefined,
|
|
||||||
kYGValueUndefined,
|
|
||||||
kYGValueUndefined,
|
|
||||||
kYGValueUndefined,
|
|
||||||
kYGValueUndefined,
|
|
||||||
kYGValueUndefined,
|
|
||||||
kYGValueUndefined,
|
|
||||||
kYGValueUndefined}};
|
|
||||||
|
|
||||||
constexpr std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
|
|
||||||
{kYGValueUndefined, kYGValueUndefined}};
|
|
||||||
|
|
||||||
struct YGStyle {
|
struct YGStyle {
|
||||||
using Dimensions = std::array<YGValue, 2>;
|
using Dimensions = facebook::yoga::detail::Values<2>;
|
||||||
|
using Edges = facebook::yoga::detail::Values<YGEdgeCount>;
|
||||||
|
|
||||||
YGDirection direction : 2;
|
YGDirection direction : 2;
|
||||||
YGFlexDirection flexDirection : 2;
|
YGFlexDirection flexDirection : 2;
|
||||||
@@ -44,13 +34,13 @@ struct YGStyle {
|
|||||||
YGFloatOptional flexGrow = {};
|
YGFloatOptional flexGrow = {};
|
||||||
YGFloatOptional flexShrink = {};
|
YGFloatOptional flexShrink = {};
|
||||||
YGValue flexBasis = kYGValueAuto;
|
YGValue flexBasis = kYGValueAuto;
|
||||||
std::array<YGValue, YGEdgeCount> margin = kYGDefaultEdgeValuesUnit;
|
Edges margin{kYGValueUndefined};
|
||||||
std::array<YGValue, YGEdgeCount> position = kYGDefaultEdgeValuesUnit;
|
Edges position{kYGValueUndefined};
|
||||||
std::array<YGValue, YGEdgeCount> padding = kYGDefaultEdgeValuesUnit;
|
Edges padding{kYGValueUndefined};
|
||||||
std::array<YGValue, YGEdgeCount> border = kYGDefaultEdgeValuesUnit;
|
Edges border{kYGValueUndefined};
|
||||||
Dimensions dimensions = {{kYGValueAuto, kYGValueAuto}};
|
Dimensions dimensions{kYGValueAuto};
|
||||||
Dimensions minDimensions = kYGDefaultDimensionValuesUnit;
|
Dimensions minDimensions{kYGValueUndefined};
|
||||||
Dimensions maxDimensions = kYGDefaultDimensionValuesUnit;
|
Dimensions maxDimensions{kYGValueUndefined};
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
YGFloatOptional aspectRatio = {};
|
YGFloatOptional aspectRatio = {};
|
||||||
|
|
||||||
|
@@ -46,6 +46,8 @@ inline bool operator==(const YGValue& lhs, const YGValue& rhs) {
|
|||||||
case YGUnitPercent:
|
case YGUnitPercent:
|
||||||
return lhs.value == rhs.value;
|
return lhs.value == rhs.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator!=(const YGValue& lhs, const YGValue& rhs) {
|
inline bool operator!=(const YGValue& lhs, const YGValue& rhs) {
|
||||||
|
@@ -42,17 +42,6 @@ extern const YGValue YGValueUndefined;
|
|||||||
extern const YGValue YGValueAuto;
|
extern const YGValue YGValueAuto;
|
||||||
extern const YGValue YGValueZero;
|
extern const YGValue YGValueZero;
|
||||||
|
|
||||||
template <std::size_t size>
|
|
||||||
bool YGValueArrayEqual(
|
|
||||||
const std::array<YGValue, size> val1,
|
|
||||||
const std::array<YGValue, size> val2) {
|
|
||||||
bool areEqual = true;
|
|
||||||
for (uint32_t i = 0; i < size && areEqual; ++i) {
|
|
||||||
areEqual = YGValueEqual(val1[i], val2[i]);
|
|
||||||
}
|
|
||||||
return areEqual;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct YGCachedMeasurement {
|
struct YGCachedMeasurement {
|
||||||
float availableWidth;
|
float availableWidth;
|
||||||
float availableHeight;
|
float availableHeight;
|
||||||
@@ -99,6 +88,64 @@ struct YGCachedMeasurement {
|
|||||||
// layouts should not require more than 16 entries to fit within the cache.
|
// layouts should not require more than 16 entries to fit within the cache.
|
||||||
#define YG_MAX_CACHED_RESULT_COUNT 16
|
#define YG_MAX_CACHED_RESULT_COUNT 16
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template <size_t Size>
|
||||||
|
class Values {
|
||||||
|
private:
|
||||||
|
std::array<YGValue, Size> values_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Values() = default;
|
||||||
|
explicit Values(const YGValue& defaultValue) noexcept {
|
||||||
|
values_.fill(defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
operator const std::array<YGValue, Size>&() const noexcept {
|
||||||
|
return values_;
|
||||||
|
}
|
||||||
|
operator std::array<YGValue, Size>&() noexcept {
|
||||||
|
return values_;
|
||||||
|
}
|
||||||
|
const YGValue& operator[](size_t i) const noexcept {
|
||||||
|
return values_[i];
|
||||||
|
}
|
||||||
|
YGValue& operator[](size_t i) noexcept {
|
||||||
|
return values_[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
YGValue get() const noexcept {
|
||||||
|
return std::get<I>(values_);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
void set(YGValue& value) noexcept {
|
||||||
|
std::get<I>(values_) = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Values& other) const noexcept {
|
||||||
|
for (size_t i = 0; i < Size; ++i) {
|
||||||
|
if (values_[i] != other.values_[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Values& operator=(const Values& other) = default;
|
||||||
|
Values& operator=(const std::array<YGValue, Size>& other) noexcept {
|
||||||
|
values_ = other;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
||||||
|
|
||||||
static const float kDefaultFlexGrow = 0.0f;
|
static const float kDefaultFlexGrow = 0.0f;
|
||||||
static const float kDefaultFlexShrink = 0.0f;
|
static const float kDefaultFlexShrink = 0.0f;
|
||||||
static const float kWebDefaultFlexShrink = 1.0f;
|
static const float kWebDefaultFlexShrink = 1.0f;
|
||||||
|
Reference in New Issue
Block a user