mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove usage of Dimension arrays and YGDimension as index (#39567)
Summary: X-link: https://github.com/facebook/yoga/pull/1402 Pull Request resolved: https://github.com/facebook/react-native/pull/39567 This change hides away most usages of YGDimension as an index. We do this for a couple reasons: 1. Right now the style interface may return a full array of resolved edge or dimension values, as a CompactValue. As we abstract away from CompactValue, and move towards ValuePool, this will no longer be the internal interface, and cheap to return. We instead change the interface to return a single value at once, which lets us resolve values lazily. 2. As we move internal usage to scoped enums, enums are not implicitly convertible to intergers (broadly a good thing). Hiding the enum as index prevents the need for callers to cast or convert to underlying. Instead of making a new version of `IdxRef` for this, I converted to a more traditional setter. I will be making similar changes later for other styles, when I hide CompactValue from the public interface. To review I would recommend filtering to changes in `xplat`, or viewing this in a single one of the OSS PRs exported. Everything apart from the below 20 files is a mirror. {F1096792573} Changelog: [Internal] Reviewed By: javache Differential Revision: D49362819 fbshipit-source-id: 30d730d78e62f36597d43f477120f65694e51ea3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
97b6829b83
commit
ea85b31354
@@ -121,8 +121,8 @@ using namespace facebook::react;
|
||||
auto &props = *sharedProps;
|
||||
props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}};
|
||||
auto &yogaStyle = props.yogaStyle;
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -136,8 +136,8 @@ using namespace facebook::react;
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{0, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{20, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -216,8 +216,8 @@ using namespace facebook::react;
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{30, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{50, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(50));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -260,8 +260,8 @@ using namespace facebook::react;
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{90, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{50, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(50));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -418,8 +418,8 @@ static ParagraphShadowNode::ConcreteState::Shared stateWithShadowNode(
|
||||
auto &props = *sharedProps;
|
||||
props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}};
|
||||
auto &yogaStyle = props.yogaStyle;
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -434,8 +434,8 @@ static ParagraphShadowNode::ConcreteState::Shared stateWithShadowNode(
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{0, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{20, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(20));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
|
||||
+28
-23
@@ -532,8 +532,10 @@ void YogaLayoutableShadowNode::setSize(Size size) const {
|
||||
ensureUnsealed();
|
||||
|
||||
auto style = yogaNode_.getStyle();
|
||||
style.dimensions()[YGDimensionWidth] = yogaStyleValueFromFloat(size.width);
|
||||
style.dimensions()[YGDimensionHeight] = yogaStyleValueFromFloat(size.height);
|
||||
style.setDimension(
|
||||
YGDimensionWidth, yoga::CompactValue::ofMaybe<YGUnitPoint>(size.width));
|
||||
style.setDimension(
|
||||
YGDimensionHeight, yoga::CompactValue::ofMaybe<YGUnitPoint>(size.height));
|
||||
yogaNode_.setStyle(style);
|
||||
yogaNode_.setDirty(true);
|
||||
}
|
||||
@@ -543,19 +545,23 @@ void YogaLayoutableShadowNode::setPadding(RectangleEdges<Float> padding) const {
|
||||
|
||||
auto style = yogaNode_.getStyle();
|
||||
|
||||
auto leftPadding = yogaStyleValueFromFloat(padding.left);
|
||||
auto topPadding = yogaStyleValueFromFloat(padding.top);
|
||||
auto rightPadding = yogaStyleValueFromFloat(padding.right);
|
||||
auto bottomPadding = yogaStyleValueFromFloat(padding.bottom);
|
||||
auto leftPadding = yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.left);
|
||||
auto topPadding = yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.top);
|
||||
auto rightPadding = yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.right);
|
||||
auto bottomPadding = yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.bottom);
|
||||
|
||||
if (leftPadding != style.padding()[YGEdgeLeft] ||
|
||||
topPadding != style.padding()[YGEdgeTop] ||
|
||||
rightPadding != style.padding()[YGEdgeRight] ||
|
||||
bottomPadding != style.padding()[YGEdgeBottom]) {
|
||||
style.padding()[YGEdgeTop] = yogaStyleValueFromFloat(padding.top);
|
||||
style.padding()[YGEdgeLeft] = yogaStyleValueFromFloat(padding.left);
|
||||
style.padding()[YGEdgeRight] = yogaStyleValueFromFloat(padding.right);
|
||||
style.padding()[YGEdgeBottom] = yogaStyleValueFromFloat(padding.bottom);
|
||||
style.padding()[YGEdgeTop] =
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.top);
|
||||
style.padding()[YGEdgeLeft] =
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.left);
|
||||
style.padding()[YGEdgeRight] =
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.right);
|
||||
style.padding()[YGEdgeBottom] =
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(padding.bottom);
|
||||
yogaNode_.setStyle(style);
|
||||
yogaNode_.setDirty(true);
|
||||
}
|
||||
@@ -624,22 +630,21 @@ void YogaLayoutableShadowNode::layoutTree(
|
||||
auto ownerWidth = yogaFloatFromFloat(maximumSize.width);
|
||||
auto ownerHeight = yogaFloatFromFloat(maximumSize.height);
|
||||
|
||||
yogaStyle.maxDimensions()[YGDimensionWidth] = std::isfinite(maximumSize.width)
|
||||
? yogaStyleValueFromFloat(maximumSize.width)
|
||||
: YGValueUndefined;
|
||||
yogaStyle.setMaxDimension(
|
||||
YGDimensionWidth,
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(maximumSize.width));
|
||||
|
||||
yogaStyle.maxDimensions()[YGDimensionHeight] =
|
||||
std::isfinite(maximumSize.height)
|
||||
? yogaStyleValueFromFloat(maximumSize.height)
|
||||
: YGValueUndefined;
|
||||
yogaStyle.setMaxDimension(
|
||||
YGDimensionHeight,
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(maximumSize.height));
|
||||
|
||||
yogaStyle.minDimensions()[YGDimensionWidth] = minimumSize.width > 0
|
||||
? yogaStyleValueFromFloat(minimumSize.width)
|
||||
: YGValueUndefined;
|
||||
yogaStyle.setMinDimension(
|
||||
YGDimensionWidth,
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(minimumSize.width));
|
||||
|
||||
yogaStyle.minDimensions()[YGDimensionHeight] = minimumSize.height > 0
|
||||
? yogaStyleValueFromFloat(minimumSize.height)
|
||||
: YGValueUndefined;
|
||||
yogaStyle.setMinDimension(
|
||||
YGDimensionHeight,
|
||||
yoga::CompactValue::ofMaybe<YGUnitPoint>(minimumSize.height));
|
||||
|
||||
auto direction =
|
||||
yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection);
|
||||
|
||||
+39
-13
@@ -181,9 +181,19 @@ static inline T const getFieldValue(
|
||||
return; \
|
||||
}
|
||||
|
||||
#define REBUILD_FIELD_YG_DIMENSION(field, widthStr, heightStr) \
|
||||
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED(field, YGDimensionWidth, widthStr); \
|
||||
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED(field, YGDimensionHeight, heightStr);
|
||||
#define REBUILD_YG_FIELD_SWITCH_CASE_INDEXED_SETTER( \
|
||||
field, setter, index, fieldName) \
|
||||
case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \
|
||||
yogaStyle.setter( \
|
||||
index, getFieldValue(context, value, ygDefaults.field(index))); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define REBUILD_FIELD_YG_DIMENSION(field, setter, widthStr, heightStr) \
|
||||
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED_SETTER( \
|
||||
field, setter, YGDimensionWidth, widthStr); \
|
||||
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED_SETTER( \
|
||||
field, setter, YGDimensionHeight, heightStr);
|
||||
|
||||
#define REBUILD_FIELD_YG_GUTTER(field, rowGapStr, columnGapStr, gapStr) \
|
||||
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED(field, YGGutterRow, rowGapStr); \
|
||||
@@ -242,9 +252,11 @@ void YogaStylableProps::setProp(
|
||||
REBUILD_FIELD_SWITCH_CASE2(positionType, "position");
|
||||
REBUILD_FIELD_YG_GUTTER(gap, "rowGap", "columnGap", "gap");
|
||||
REBUILD_FIELD_SWITCH_CASE_YSP(aspectRatio);
|
||||
REBUILD_FIELD_YG_DIMENSION(dimensions, "width", "height");
|
||||
REBUILD_FIELD_YG_DIMENSION(minDimensions, "minWidth", "minHeight");
|
||||
REBUILD_FIELD_YG_DIMENSION(maxDimensions, "maxWidth", "maxHeight");
|
||||
REBUILD_FIELD_YG_DIMENSION(dimension, setDimension, "width", "height");
|
||||
REBUILD_FIELD_YG_DIMENSION(
|
||||
minDimension, setMinDimension, "minWidth", "minHeight");
|
||||
REBUILD_FIELD_YG_DIMENSION(
|
||||
maxDimension, setMaxDimension, "maxWidth", "maxHeight");
|
||||
REBUILD_FIELD_YG_EDGES_POSITION();
|
||||
REBUILD_FIELD_YG_EDGES(margin, "margin", "");
|
||||
REBUILD_FIELD_YG_EDGES(padding, "padding", "");
|
||||
@@ -336,15 +348,29 @@ SharedDebugStringConvertibleList YogaStylableProps::getDebugProps() const {
|
||||
debugStringConvertibleItem(
|
||||
"border", yogaStyle.border(), defaultYogaStyle.border()),
|
||||
debugStringConvertibleItem(
|
||||
"dimensions", yogaStyle.dimensions(), defaultYogaStyle.dimensions()),
|
||||
"width",
|
||||
yogaStyle.dimension(YGDimensionWidth),
|
||||
defaultYogaStyle.dimension(YGDimensionWidth)),
|
||||
debugStringConvertibleItem(
|
||||
"minDimensions",
|
||||
yogaStyle.minDimensions(),
|
||||
defaultYogaStyle.minDimensions()),
|
||||
"height",
|
||||
yogaStyle.dimension(YGDimensionHeight),
|
||||
defaultYogaStyle.dimension(YGDimensionHeight)),
|
||||
debugStringConvertibleItem(
|
||||
"maxDimensions",
|
||||
yogaStyle.maxDimensions(),
|
||||
defaultYogaStyle.maxDimensions()),
|
||||
"minWidth",
|
||||
yogaStyle.minDimension(YGDimensionWidth),
|
||||
defaultYogaStyle.minDimension(YGDimensionWidth)),
|
||||
debugStringConvertibleItem(
|
||||
"minHeight",
|
||||
yogaStyle.minDimension(YGDimensionHeight),
|
||||
defaultYogaStyle.minDimension(YGDimensionHeight)),
|
||||
debugStringConvertibleItem(
|
||||
"maxWidth",
|
||||
yogaStyle.maxDimension(YGDimensionWidth),
|
||||
defaultYogaStyle.maxDimension(YGDimensionWidth)),
|
||||
debugStringConvertibleItem(
|
||||
"maxHeight",
|
||||
yogaStyle.maxDimension(YGDimensionHeight),
|
||||
defaultYogaStyle.maxDimension(YGDimensionHeight)),
|
||||
debugStringConvertibleItem(
|
||||
"aspectRatio",
|
||||
yogaStyle.aspectRatio(),
|
||||
|
||||
@@ -81,22 +81,6 @@ inline yoga::FloatOptional yogaOptionalFloatFromFloat(Float value) {
|
||||
return yoga::FloatOptional((float)value);
|
||||
}
|
||||
|
||||
/*
|
||||
* `YGValue` <-> `React Native's `Float`
|
||||
*
|
||||
* `YGValue` represents optional dimensionful (a real number and some unit, e.g.
|
||||
* pixels).
|
||||
*/
|
||||
inline YGValue yogaStyleValueFromFloat(
|
||||
const Float& value,
|
||||
YGUnit unit = YGUnitPoint) {
|
||||
if (!std::isfinite(value)) {
|
||||
return YGValueUndefined;
|
||||
}
|
||||
|
||||
return {(float)value, unit};
|
||||
}
|
||||
|
||||
inline std::optional<Float> optionalFloatFromYogaValue(
|
||||
const YGValue value,
|
||||
std::optional<Float> base = {}) {
|
||||
@@ -409,7 +393,7 @@ inline void fromRawValue(
|
||||
const RawValue& value,
|
||||
yoga::Style::ValueRepr& result) {
|
||||
if (value.hasType<Float>()) {
|
||||
result = yogaStyleValueFromFloat((Float)value);
|
||||
result = yoga::CompactValue::ofMaybe<YGUnitPoint>((float)value);
|
||||
return;
|
||||
} else if (value.hasType<std::string>()) {
|
||||
const auto stringValue = (std::string)value;
|
||||
|
||||
+53
-43
@@ -17,28 +17,6 @@ namespace facebook::react {
|
||||
|
||||
// Nearly this entire file can be deleted when iterator-style Prop parsing
|
||||
// ships fully for View
|
||||
static inline yoga::Style::Dimensions convertRawProp(
|
||||
const PropsParserContext& context,
|
||||
const RawProps& rawProps,
|
||||
const char* widthName,
|
||||
const char* heightName,
|
||||
const yoga::Style::Dimensions& sourceValue,
|
||||
const yoga::Style::Dimensions& defaultValue) {
|
||||
auto dimensions = defaultValue;
|
||||
dimensions[YGDimensionWidth] = convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
widthName,
|
||||
sourceValue[YGDimensionWidth],
|
||||
defaultValue[YGDimensionWidth]);
|
||||
dimensions[YGDimensionHeight] = convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
heightName,
|
||||
sourceValue[YGDimensionHeight],
|
||||
defaultValue[YGDimensionHeight]);
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
static inline yoga::Style::Edges convertRawProp(
|
||||
const PropsParserContext& context,
|
||||
@@ -294,33 +272,65 @@ static inline yoga::Style convertRawProp(
|
||||
"Width",
|
||||
sourceValue.border(),
|
||||
yogaStyle.border());
|
||||
yogaStyle.dimensions() = convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"width",
|
||||
"height",
|
||||
sourceValue.dimensions(),
|
||||
yogaStyle.dimensions());
|
||||
yogaStyle.minDimensions() = convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"minWidth",
|
||||
"minHeight",
|
||||
sourceValue.minDimensions(),
|
||||
yogaStyle.minDimensions());
|
||||
yogaStyle.maxDimensions() = convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"maxWidth",
|
||||
"maxHeight",
|
||||
sourceValue.maxDimensions(),
|
||||
yogaStyle.maxDimensions());
|
||||
|
||||
yogaStyle.setDimension(
|
||||
YGDimensionWidth,
|
||||
convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"width",
|
||||
sourceValue.dimension(YGDimensionWidth),
|
||||
{}));
|
||||
yogaStyle.setDimension(
|
||||
YGDimensionHeight,
|
||||
convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"height",
|
||||
sourceValue.dimension(YGDimensionHeight),
|
||||
{}));
|
||||
|
||||
yogaStyle.setMinDimension(
|
||||
YGDimensionWidth,
|
||||
convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"minWidth",
|
||||
sourceValue.minDimension(YGDimensionWidth),
|
||||
{}));
|
||||
yogaStyle.setMinDimension(
|
||||
YGDimensionHeight,
|
||||
convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"minHeight",
|
||||
sourceValue.minDimension(YGDimensionHeight),
|
||||
{}));
|
||||
|
||||
yogaStyle.setMaxDimension(
|
||||
YGDimensionWidth,
|
||||
convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"maxWidth",
|
||||
sourceValue.maxDimension(YGDimensionWidth),
|
||||
{}));
|
||||
yogaStyle.setMaxDimension(
|
||||
YGDimensionHeight,
|
||||
convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"maxHeight",
|
||||
sourceValue.maxDimension(YGDimensionHeight),
|
||||
{}));
|
||||
|
||||
yogaStyle.aspectRatio() = convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"aspectRatio",
|
||||
sourceValue.aspectRatio(),
|
||||
yogaStyle.aspectRatio());
|
||||
|
||||
return yogaStyle;
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -77,8 +77,8 @@ class LayoutTest : public ::testing::Test {
|
||||
auto &props = *sharedProps;
|
||||
props.layoutConstraints = LayoutConstraints{{0,0}, {500, 500}};
|
||||
auto &yogaStyle = props.yogaStyle;
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{200, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -90,8 +90,8 @@ class LayoutTest : public ::testing::Test {
|
||||
auto &props = *sharedProps;
|
||||
auto &yogaStyle = props.yogaStyle;
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{50, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{50, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(50));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(50));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -105,8 +105,8 @@ class LayoutTest : public ::testing::Test {
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{10, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{10, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{30, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{90, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(30));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(90));
|
||||
|
||||
if (testCase == TRANSFORM_SCALE) {
|
||||
props.transform = props.transform * Transform::Scale(2, 2, 1);
|
||||
@@ -138,8 +138,8 @@ class LayoutTest : public ::testing::Test {
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{10, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{10, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{110, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{20, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(110));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(20));
|
||||
return sharedProps;
|
||||
})
|
||||
.children({
|
||||
@@ -153,8 +153,8 @@ class LayoutTest : public ::testing::Test {
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{70, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{-50, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{30, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{60, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(30));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(60));
|
||||
return sharedProps;
|
||||
})
|
||||
}),
|
||||
@@ -168,8 +168,8 @@ class LayoutTest : public ::testing::Test {
|
||||
yogaStyle.positionType() = yoga::PositionType::Absolute;
|
||||
yogaStyle.position()[YGEdgeLeft] = YGValue{-60, YGUnitPoint};
|
||||
yogaStyle.position()[YGEdgeTop] = YGValue{50, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionWidth] = YGValue{70, YGUnitPoint};
|
||||
yogaStyle.dimensions()[YGDimensionHeight] = YGValue{20, YGUnitPoint};
|
||||
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(70));
|
||||
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(20));
|
||||
return sharedProps;
|
||||
})
|
||||
})
|
||||
|
||||
@@ -419,6 +419,15 @@ void updateIndexedStyleProp(
|
||||
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
||||
}
|
||||
|
||||
template <auto GetterT, auto SetterT, typename IdxT>
|
||||
void updateIndexedStyleProp(YGNodeRef node, IdxT idx, CompactValue value) {
|
||||
updateStyle(
|
||||
resolveRef(node),
|
||||
value,
|
||||
[idx](Style& s, CompactValue x) { return (s.*GetterT)(idx) != x; },
|
||||
[idx](Style& s, CompactValue x) { (s.*SetterT)(idx, x); });
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// MSVC has trouble inferring the return type of pointer to member functions
|
||||
@@ -664,98 +673,98 @@ void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
|
||||
|
||||
void YGNodeStyleSetWidth(YGNodeRef node, float points) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetWidthAuto(YGNodeRef node) {
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionWidth, CompactValue::ofAuto());
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionWidth, CompactValue::ofAuto());
|
||||
}
|
||||
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().dimensions()[YGDimensionWidth];
|
||||
return resolveRef(node)->getStyle().dimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetHeightAuto(YGNodeRef node) {
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionHeight, CompactValue::ofAuto());
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionHeight, CompactValue::ofAuto());
|
||||
}
|
||||
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().dimensions()[YGDimensionHeight];
|
||||
return resolveRef(node)->getStyle().dimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(minWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(minWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().minDimensions()[YGDimensionWidth];
|
||||
return resolveRef(node)->getStyle().minDimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(minHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetMinHeightPercent(
|
||||
const YGNodeRef node,
|
||||
const float minHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(minHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().minDimensions()[YGDimensionHeight];
|
||||
return resolveRef(node)->getStyle().minDimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionWidth];
|
||||
return resolveRef(node)->getStyle().maxDimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetMaxHeightPercent(
|
||||
const YGNodeRef node,
|
||||
const float maxHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionHeight];
|
||||
return resolveRef(node)->getStyle().maxDimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -808,11 +817,11 @@ float YGNodeLayoutGetBottom(const YGNodeConstRef node) {
|
||||
}
|
||||
|
||||
float YGNodeLayoutGetWidth(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getLayout().dimensions[YGDimensionWidth];
|
||||
return resolveRef(node)->getLayout().dimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
float YGNodeLayoutGetHeight(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getLayout().dimensions[YGDimensionHeight];
|
||||
return resolveRef(node)->getLayout().dimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
YGDirection YGNodeLayoutGetDirection(const YGNodeConstRef node) {
|
||||
|
||||
@@ -19,8 +19,8 @@ float calculateBaseline(const yoga::Node* node) {
|
||||
Event::publish<Event::NodeBaselineStart>(node);
|
||||
|
||||
const float baseline = node->baseline(
|
||||
node->getLayout().measuredDimensions[YGDimensionWidth],
|
||||
node->getLayout().measuredDimensions[YGDimensionHeight]);
|
||||
node->getLayout().measuredDimension(YGDimensionWidth),
|
||||
node->getLayout().measuredDimension(YGDimensionHeight));
|
||||
|
||||
Event::publish<Event::NodeBaselineEnd>(node);
|
||||
|
||||
@@ -53,7 +53,7 @@ float calculateBaseline(const yoga::Node* node) {
|
||||
}
|
||||
|
||||
if (baselineChild == nullptr) {
|
||||
return node->getLayout().measuredDimensions[YGDimensionHeight];
|
||||
return node->getLayout().measuredDimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
const float baseline = calculateBaseline(baselineChild);
|
||||
|
||||
@@ -35,14 +35,14 @@ inline FloatOptional boundAxisWithinMinAndMax(
|
||||
|
||||
if (isColumn(axis)) {
|
||||
min = yoga::resolveValue(
|
||||
node->getStyle().minDimensions()[YGDimensionHeight], axisSize);
|
||||
node->getStyle().minDimension(YGDimensionHeight), axisSize);
|
||||
max = yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[YGDimensionHeight], axisSize);
|
||||
node->getStyle().maxDimension(YGDimensionHeight), axisSize);
|
||||
} else if (isRow(axis)) {
|
||||
min = yoga::resolveValue(
|
||||
node->getStyle().minDimensions()[YGDimensionWidth], axisSize);
|
||||
node->getStyle().minDimension(YGDimensionWidth), axisSize);
|
||||
max = yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[YGDimensionWidth], axisSize);
|
||||
node->getStyle().maxDimension(YGDimensionWidth), axisSize);
|
||||
}
|
||||
|
||||
if (max >= FloatOptional{0} && value > max) {
|
||||
|
||||
@@ -53,7 +53,7 @@ static inline float dimensionWithMargin(
|
||||
const yoga::Node* const node,
|
||||
const FlexDirection axis,
|
||||
const float widthSize) {
|
||||
return node->getLayout().measuredDimensions[dimension(axis)] +
|
||||
return node->getLayout().measuredDimension(dimension(axis)) +
|
||||
(node->getLeadingMargin(axis, widthSize) +
|
||||
node->getTrailingMargin(axis, widthSize))
|
||||
.unwrap();
|
||||
@@ -79,7 +79,7 @@ static inline bool styleDefinesDimension(
|
||||
static inline bool isLayoutDimensionDefined(
|
||||
const yoga::Node* const node,
|
||||
const FlexDirection axis) {
|
||||
const float value = node->getLayout().measuredDimensions[dimension(axis)];
|
||||
const float value = node->getLayout().measuredDimension(dimension(axis));
|
||||
return !yoga::isUndefined(value) && value >= 0.0f;
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ static void setChildTrailingPosition(
|
||||
const yoga::Node* const node,
|
||||
yoga::Node* const child,
|
||||
const FlexDirection axis) {
|
||||
const float size = child->getLayout().measuredDimensions[dimension(axis)];
|
||||
const float size = child->getLayout().measuredDimension(dimension(axis));
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(axis)] - size -
|
||||
node->getLayout().measuredDimension(dimension(axis)) - size -
|
||||
child->getLayout().position[leadingEdge(axis)],
|
||||
trailingEdge(axis));
|
||||
}
|
||||
@@ -103,7 +103,7 @@ static void constrainMaxSizeForMode(
|
||||
float* size) {
|
||||
const FloatOptional maxSize =
|
||||
yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[dimension(axis)], ownerAxisSize) +
|
||||
node->getStyle().maxDimension(dimension(axis)), ownerAxisSize) +
|
||||
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
||||
switch (*mode) {
|
||||
case MeasureMode::Exactly:
|
||||
@@ -169,7 +169,7 @@ static void computeFlexBasisForChild(
|
||||
|
||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionWidth], ownerWidth),
|
||||
child->getResolvedDimension(YGDimensionWidth), ownerWidth),
|
||||
paddingAndBorder));
|
||||
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
||||
// The height is definite, so use that as the flex basis.
|
||||
@@ -177,7 +177,7 @@ static void computeFlexBasisForChild(
|
||||
paddingAndBorderForAxis(child, FlexDirection::Column, ownerWidth));
|
||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionHeight], ownerHeight),
|
||||
child->getResolvedDimension(YGDimensionHeight), ownerHeight),
|
||||
paddingAndBorder));
|
||||
} else {
|
||||
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
||||
@@ -195,7 +195,7 @@ static void computeFlexBasisForChild(
|
||||
if (isRowStyleDimDefined) {
|
||||
childWidth =
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionWidth], ownerWidth)
|
||||
child->getResolvedDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap() +
|
||||
marginRow;
|
||||
childWidthMeasureMode = MeasureMode::Exactly;
|
||||
@@ -203,7 +203,7 @@ static void computeFlexBasisForChild(
|
||||
if (isColumnStyleDimDefined) {
|
||||
childHeight =
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionHeight], ownerHeight)
|
||||
child->getResolvedDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap() +
|
||||
marginColumn;
|
||||
childHeightMeasureMode = MeasureMode::Exactly;
|
||||
@@ -309,7 +309,7 @@ static void computeFlexBasisForChild(
|
||||
generationCount);
|
||||
|
||||
child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)],
|
||||
child->getLayout().measuredDimension(dimension(mainAxis)),
|
||||
paddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
||||
}
|
||||
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
||||
@@ -340,16 +340,16 @@ static void layoutAbsoluteChild(
|
||||
child->getMarginForAxis(FlexDirection::Column, width).unwrap();
|
||||
|
||||
if (styleDefinesDimension(child, FlexDirection::Row, width)) {
|
||||
childWidth = yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionWidth], width)
|
||||
.unwrap() +
|
||||
childWidth =
|
||||
yoga::resolveValue(child->getResolvedDimension(YGDimensionWidth), width)
|
||||
.unwrap() +
|
||||
marginRow;
|
||||
} else {
|
||||
// If the child doesn't have a specified width, compute the width based on
|
||||
// the left/right offsets if they're defined.
|
||||
if (child->isLeadingPositionDefined(FlexDirection::Row) &&
|
||||
child->isTrailingPosDefined(FlexDirection::Row)) {
|
||||
childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] -
|
||||
childWidth = node->getLayout().measuredDimension(YGDimensionWidth) -
|
||||
(node->getLeadingBorder(FlexDirection::Row) +
|
||||
node->getTrailingBorder(FlexDirection::Row)) -
|
||||
(child->getLeadingPosition(FlexDirection::Row, width) +
|
||||
@@ -362,7 +362,7 @@ static void layoutAbsoluteChild(
|
||||
|
||||
if (styleDefinesDimension(child, FlexDirection::Column, height)) {
|
||||
childHeight = yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionHeight], height)
|
||||
child->getResolvedDimension(YGDimensionHeight), height)
|
||||
.unwrap() +
|
||||
marginColumn;
|
||||
} else {
|
||||
@@ -370,7 +370,7 @@ static void layoutAbsoluteChild(
|
||||
// the top/bottom offsets if they're defined.
|
||||
if (child->isLeadingPositionDefined(FlexDirection::Column) &&
|
||||
child->isTrailingPosDefined(FlexDirection::Column)) {
|
||||
childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] -
|
||||
childHeight = node->getLayout().measuredDimension(YGDimensionHeight) -
|
||||
(node->getLeadingBorder(FlexDirection::Column) +
|
||||
node->getTrailingBorder(FlexDirection::Column)) -
|
||||
(child->getLeadingPosition(FlexDirection::Column, height) +
|
||||
@@ -431,9 +431,9 @@ static void layoutAbsoluteChild(
|
||||
layoutMarkerData,
|
||||
depth,
|
||||
generationCount);
|
||||
childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] +
|
||||
childWidth = child->getLayout().measuredDimension(YGDimensionWidth) +
|
||||
child->getMarginForAxis(FlexDirection::Row, width).unwrap();
|
||||
childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] +
|
||||
childHeight = child->getLayout().measuredDimension(YGDimensionHeight) +
|
||||
child->getMarginForAxis(FlexDirection::Column, width).unwrap();
|
||||
}
|
||||
|
||||
@@ -455,8 +455,8 @@ static void layoutAbsoluteChild(
|
||||
if (child->isTrailingPosDefined(mainAxis) &&
|
||||
!child->isLeadingPositionDefined(mainAxis)) {
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
node->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
node->getTrailingBorder(mainAxis) -
|
||||
child->getTrailingMargin(mainAxis, isMainAxisRow ? width : height)
|
||||
.unwrap() -
|
||||
@@ -467,16 +467,16 @@ static void layoutAbsoluteChild(
|
||||
!child->isLeadingPositionDefined(mainAxis) &&
|
||||
node->getStyle().justifyContent() == Justify::Center) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)]) /
|
||||
(node->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(mainAxis))) /
|
||||
2.0f,
|
||||
leadingEdge(mainAxis));
|
||||
} else if (
|
||||
!child->isLeadingPositionDefined(mainAxis) &&
|
||||
node->getStyle().justifyContent() == Justify::FlexEnd) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)]),
|
||||
(node->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(mainAxis))),
|
||||
leadingEdge(mainAxis));
|
||||
} else if (
|
||||
node->getConfig()->isExperimentalFeatureEnabled(
|
||||
@@ -485,13 +485,13 @@ static void layoutAbsoluteChild(
|
||||
child->setLayoutPosition(
|
||||
child->getLeadingPosition(
|
||||
mainAxis,
|
||||
node->getLayout().measuredDimensions[dimension(mainAxis)])
|
||||
node->getLayout().measuredDimension(dimension(mainAxis)))
|
||||
.unwrap() +
|
||||
node->getLeadingBorder(mainAxis) +
|
||||
child
|
||||
->getLeadingMargin(
|
||||
mainAxis,
|
||||
node->getLayout().measuredDimensions[dimension(mainAxis)])
|
||||
node->getLayout().measuredDimension(dimension(mainAxis)))
|
||||
.unwrap(),
|
||||
leadingEdge(mainAxis));
|
||||
}
|
||||
@@ -499,8 +499,8 @@ static void layoutAbsoluteChild(
|
||||
if (child->isTrailingPosDefined(crossAxis) &&
|
||||
!child->isLeadingPositionDefined(crossAxis)) {
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
node->getTrailingBorder(crossAxis) -
|
||||
child->getTrailingMargin(crossAxis, isMainAxisRow ? height : width)
|
||||
.unwrap() -
|
||||
@@ -513,8 +513,8 @@ static void layoutAbsoluteChild(
|
||||
!child->isLeadingPositionDefined(crossAxis) &&
|
||||
resolveChildAlignment(node, child) == Align::Center) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)]) /
|
||||
(node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(crossAxis))) /
|
||||
2.0f,
|
||||
leadingEdge(crossAxis));
|
||||
} else if (
|
||||
@@ -522,8 +522,8 @@ static void layoutAbsoluteChild(
|
||||
((resolveChildAlignment(node, child) == Align::FlexEnd) ^
|
||||
(node->getStyle().flexWrap() == Wrap::WrapReverse))) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)]),
|
||||
(node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(crossAxis))),
|
||||
leadingEdge(crossAxis));
|
||||
} else if (
|
||||
node->getConfig()->isExperimentalFeatureEnabled(
|
||||
@@ -532,13 +532,13 @@ static void layoutAbsoluteChild(
|
||||
child->setLayoutPosition(
|
||||
child->getLeadingPosition(
|
||||
crossAxis,
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)])
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)))
|
||||
.unwrap() +
|
||||
node->getLeadingBorder(crossAxis) +
|
||||
child
|
||||
->getLeadingMargin(
|
||||
crossAxis,
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)])
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)))
|
||||
.unwrap(),
|
||||
leadingEdge(crossAxis));
|
||||
}
|
||||
@@ -746,14 +746,14 @@ static float calculateAvailableInnerDimension(
|
||||
if (!yoga::isUndefined(availableInnerDim)) {
|
||||
// We want to make sure our available height does not violate min and max
|
||||
// constraints
|
||||
const FloatOptional minDimensionOptional = yoga::resolveValue(
|
||||
node->getStyle().minDimensions()[dimension], ownerDim);
|
||||
const FloatOptional minDimensionOptional =
|
||||
yoga::resolveValue(node->getStyle().minDimension(dimension), ownerDim);
|
||||
const float minInnerDim = minDimensionOptional.isUndefined()
|
||||
? 0.0f
|
||||
: minDimensionOptional.unwrap() - paddingAndBorder;
|
||||
|
||||
const FloatOptional maxDimensionOptional = yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[dimension], ownerDim);
|
||||
const FloatOptional maxDimensionOptional =
|
||||
yoga::resolveValue(node->getStyle().maxDimension(dimension), ownerDim);
|
||||
|
||||
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
||||
? FLT_MAX
|
||||
@@ -1220,9 +1220,9 @@ static void justifyMainAxis(
|
||||
// remainingFreeSpace is 0 when min main dimension is not given
|
||||
if (measureModeMainDim == MeasureMode::AtMost &&
|
||||
flexLine.layout.remainingFreeSpace > 0) {
|
||||
if (!style.minDimensions()[dimension(mainAxis)].isUndefined() &&
|
||||
if (!style.minDimension(dimension(mainAxis)).isUndefined() &&
|
||||
!yoga::resolveValue(
|
||||
style.minDimensions()[dimension(mainAxis)], mainAxisownerSize)
|
||||
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
|
||||
.isUndefined()) {
|
||||
// This condition makes sure that if the size of main dimension(after
|
||||
// considering child nodes main dim, leading and trailing padding etc)
|
||||
@@ -1233,7 +1233,7 @@ static void justifyMainAxis(
|
||||
// can be laid out, it will exclude space consumed by padding and border.
|
||||
const float minAvailableMainDim =
|
||||
yoga::resolveValue(
|
||||
style.minDimensions()[dimension(mainAxis)], mainAxisownerSize)
|
||||
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
|
||||
.unwrap() -
|
||||
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
|
||||
const float occupiedSpaceByChildNodes =
|
||||
@@ -1373,7 +1373,7 @@ static void justifyMainAxis(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
.unwrap();
|
||||
const float descent =
|
||||
child->getLayout().measuredDimensions[YGDimensionHeight] +
|
||||
child->getLayout().measuredDimension(YGDimensionHeight) +
|
||||
child
|
||||
->getMarginForAxis(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
@@ -1723,22 +1723,21 @@ static void calculateLayoutImpl(
|
||||
// If we don't measure with exact main dimension we want to ensure we don't
|
||||
// violate min and max
|
||||
if (measureModeMainDim != MeasureMode::Exactly) {
|
||||
const auto& minDimensions = node->getStyle().minDimensions();
|
||||
const auto& maxDimensions = node->getStyle().maxDimensions();
|
||||
const auto& style = node->getStyle();
|
||||
const float minInnerWidth =
|
||||
yoga::resolveValue(minDimensions[YGDimensionWidth], ownerWidth)
|
||||
yoga::resolveValue(style.minDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisRow;
|
||||
const float maxInnerWidth =
|
||||
yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
|
||||
yoga::resolveValue(style.maxDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisRow;
|
||||
const float minInnerHeight =
|
||||
yoga::resolveValue(minDimensions[YGDimensionHeight], ownerHeight)
|
||||
yoga::resolveValue(style.minDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisColumn;
|
||||
const float maxInnerHeight =
|
||||
yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
|
||||
yoga::resolveValue(style.maxDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisColumn;
|
||||
|
||||
@@ -1911,7 +1910,7 @@ static void calculateLayoutImpl(
|
||||
if (!styleDefinesDimension(
|
||||
child, crossAxis, availableInnerCrossDim)) {
|
||||
float childMainSize =
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)];
|
||||
child->getLayout().measuredDimension(dimension(mainAxis));
|
||||
const auto& childStyle = child->getStyle();
|
||||
float childCrossSize = !childStyle.aspectRatio().isUndefined()
|
||||
? child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||
@@ -2079,7 +2078,7 @@ static void calculateLayoutImpl(
|
||||
if (isLayoutDimensionDefined(child, crossAxis)) {
|
||||
lineHeight = yoga::maxOrDefined(
|
||||
lineHeight,
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)] +
|
||||
child->getLayout().measuredDimension(dimension(crossAxis)) +
|
||||
child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||
.unwrap());
|
||||
}
|
||||
@@ -2090,7 +2089,7 @@ static void calculateLayoutImpl(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
.unwrap();
|
||||
const float descent =
|
||||
child->getLayout().measuredDimensions[YGDimensionHeight] +
|
||||
child->getLayout().measuredDimension(YGDimensionHeight) +
|
||||
child
|
||||
->getMarginForAxis(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
@@ -2130,14 +2129,14 @@ static void calculateLayoutImpl(
|
||||
currentLead + lineHeight -
|
||||
child->getTrailingMargin(crossAxis, availableInnerWidth)
|
||||
.unwrap() -
|
||||
child->getLayout()
|
||||
.measuredDimensions[dimension(crossAxis)],
|
||||
child->getLayout().measuredDimension(
|
||||
dimension(crossAxis)),
|
||||
leadingEdge(crossAxis));
|
||||
break;
|
||||
}
|
||||
case Align::Center: {
|
||||
float childHeight =
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)];
|
||||
child->getLayout().measuredDimension(dimension(crossAxis));
|
||||
|
||||
child->setLayoutPosition(
|
||||
currentLead + (lineHeight - childHeight) / 2,
|
||||
@@ -2156,27 +2155,27 @@ static void calculateLayoutImpl(
|
||||
if (!styleDefinesDimension(
|
||||
child, crossAxis, availableInnerCrossDim)) {
|
||||
const float childWidth = isMainAxisRow
|
||||
? (child->getLayout()
|
||||
.measuredDimensions[YGDimensionWidth] +
|
||||
? (child->getLayout().measuredDimension(
|
||||
YGDimensionWidth) +
|
||||
child->getMarginForAxis(mainAxis, availableInnerWidth)
|
||||
.unwrap())
|
||||
: lineHeight;
|
||||
|
||||
const float childHeight = !isMainAxisRow
|
||||
? (child->getLayout()
|
||||
.measuredDimensions[YGDimensionHeight] +
|
||||
? (child->getLayout().measuredDimension(
|
||||
YGDimensionHeight) +
|
||||
child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||
.unwrap())
|
||||
: lineHeight;
|
||||
|
||||
if (!(yoga::inexactEquals(
|
||||
childWidth,
|
||||
child->getLayout()
|
||||
.measuredDimensions[YGDimensionWidth]) &&
|
||||
child->getLayout().measuredDimension(
|
||||
YGDimensionWidth)) &&
|
||||
yoga::inexactEquals(
|
||||
childHeight,
|
||||
child->getLayout()
|
||||
.measuredDimensions[YGDimensionHeight]))) {
|
||||
child->getLayout().measuredDimension(
|
||||
YGDimensionHeight)))) {
|
||||
calculateLayoutInternal(
|
||||
child,
|
||||
childWidth,
|
||||
@@ -2307,9 +2306,9 @@ static void calculateLayoutImpl(
|
||||
const auto child = node->getChild(i);
|
||||
if (child->getStyle().positionType() != PositionType::Absolute) {
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().position[leadingEdge(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)],
|
||||
child->getLayout().measuredDimension(dimension(crossAxis)),
|
||||
leadingEdge(crossAxis));
|
||||
}
|
||||
}
|
||||
@@ -2330,11 +2329,11 @@ static void calculateLayoutImpl(
|
||||
node,
|
||||
child,
|
||||
absolutePercentageAgainstPaddingEdge
|
||||
? node->getLayout().measuredDimensions[YGDimensionWidth]
|
||||
? node->getLayout().measuredDimension(YGDimensionWidth)
|
||||
: availableInnerWidth,
|
||||
isMainAxisRow ? measureModeMainDim : measureModeCrossDim,
|
||||
absolutePercentageAgainstPaddingEdge
|
||||
? node->getLayout().measuredDimensions[YGDimensionHeight]
|
||||
? node->getLayout().measuredDimension(YGDimensionHeight)
|
||||
: availableInnerHeight,
|
||||
direction,
|
||||
layoutMarkerData,
|
||||
@@ -2516,9 +2515,10 @@ bool calculateLayoutInternal(
|
||||
}
|
||||
|
||||
if (!needToVisitNode && cachedResults != nullptr) {
|
||||
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
||||
layout->measuredDimensions[YGDimensionHeight] =
|
||||
cachedResults->computedHeight;
|
||||
layout->setMeasuredDimension(
|
||||
YGDimensionWidth, cachedResults->computedWidth);
|
||||
layout->setMeasuredDimension(
|
||||
YGDimensionHeight, cachedResults->computedHeight);
|
||||
|
||||
(performLayout ? layoutMarkerData.cachedLayouts
|
||||
: layoutMarkerData.cachedMeasures) += 1;
|
||||
@@ -2594,8 +2594,8 @@ bool calculateLayoutInternal(
|
||||
"wm: %s, hm: %s, d: (%f, %f) %s\n",
|
||||
measureModeName(widthMeasureMode, performLayout),
|
||||
measureModeName(heightMeasureMode, performLayout),
|
||||
layout->measuredDimensions[YGDimensionWidth],
|
||||
layout->measuredDimensions[YGDimensionHeight],
|
||||
layout->measuredDimension(YGDimensionWidth),
|
||||
layout->measuredDimension(YGDimensionHeight),
|
||||
LayoutPassReasonToString(reason));
|
||||
}
|
||||
|
||||
@@ -2630,18 +2630,18 @@ bool calculateLayoutInternal(
|
||||
newCacheEntry->widthMeasureMode = widthMeasureMode;
|
||||
newCacheEntry->heightMeasureMode = heightMeasureMode;
|
||||
newCacheEntry->computedWidth =
|
||||
layout->measuredDimensions[YGDimensionWidth];
|
||||
layout->measuredDimension(YGDimensionWidth);
|
||||
newCacheEntry->computedHeight =
|
||||
layout->measuredDimensions[YGDimensionHeight];
|
||||
layout->measuredDimension(YGDimensionHeight);
|
||||
}
|
||||
}
|
||||
|
||||
if (performLayout) {
|
||||
node->setLayoutDimension(
|
||||
node->getLayout().measuredDimensions[YGDimensionWidth],
|
||||
node->getLayout().measuredDimension(YGDimensionWidth),
|
||||
YGDimensionWidth);
|
||||
node->setLayoutDimension(
|
||||
node->getLayout().measuredDimensions[YGDimensionHeight],
|
||||
node->getLayout().measuredDimension(YGDimensionHeight),
|
||||
YGDimensionHeight);
|
||||
|
||||
node->setHasNewLayout(true);
|
||||
@@ -2679,7 +2679,7 @@ void calculateLayout(
|
||||
node->resolveDimension();
|
||||
float width = YGUndefined;
|
||||
MeasureMode widthMeasureMode = MeasureMode::Undefined;
|
||||
const auto& maxDimensions = node->getStyle().maxDimensions();
|
||||
const auto& style = node->getStyle();
|
||||
if (styleDefinesDimension(node, FlexDirection::Row, ownerWidth)) {
|
||||
width = (yoga::resolveValue(
|
||||
node->getResolvedDimension(dimension(FlexDirection::Row)),
|
||||
@@ -2687,9 +2687,10 @@ void calculateLayout(
|
||||
node->getMarginForAxis(FlexDirection::Row, ownerWidth))
|
||||
.unwrap();
|
||||
widthMeasureMode = MeasureMode::Exactly;
|
||||
} else if (!yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
|
||||
} else if (!yoga::resolveValue(
|
||||
style.maxDimension(YGDimensionWidth), ownerWidth)
|
||||
.isUndefined()) {
|
||||
width = yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
|
||||
width = yoga::resolveValue(style.maxDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap();
|
||||
widthMeasureMode = MeasureMode::AtMost;
|
||||
} else {
|
||||
@@ -2707,10 +2708,12 @@ void calculateLayout(
|
||||
node->getMarginForAxis(FlexDirection::Column, ownerWidth))
|
||||
.unwrap();
|
||||
heightMeasureMode = MeasureMode::Exactly;
|
||||
} else if (!yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
|
||||
} else if (!yoga::resolveValue(
|
||||
style.maxDimension(YGDimensionHeight), ownerHeight)
|
||||
.isUndefined()) {
|
||||
height = yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
|
||||
.unwrap();
|
||||
height =
|
||||
yoga::resolveValue(style.maxDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap();
|
||||
heightMeasureMode = MeasureMode::AtMost;
|
||||
} else {
|
||||
height = ownerHeight;
|
||||
|
||||
@@ -71,8 +71,8 @@ void roundLayoutResultsToPixelGrid(
|
||||
const double nodeLeft = node->getLayout().position[YGEdgeLeft];
|
||||
const double nodeTop = node->getLayout().position[YGEdgeTop];
|
||||
|
||||
const double nodeWidth = node->getLayout().dimensions[YGDimensionWidth];
|
||||
const double nodeHeight = node->getLayout().dimensions[YGDimensionHeight];
|
||||
const double nodeWidth = node->getLayout().dimension(YGDimensionWidth);
|
||||
const double nodeHeight = node->getLayout().dimension(YGDimensionHeight);
|
||||
|
||||
const double absoluteNodeLeft = absoluteLeft + nodeLeft;
|
||||
const double absoluteNodeTop = absoluteTop + nodeTop;
|
||||
|
||||
@@ -127,9 +127,9 @@ void nodeToString(
|
||||
if ((options & PrintOptions::Layout) == PrintOptions::Layout) {
|
||||
appendFormattedString(str, "layout=\"");
|
||||
appendFormattedString(
|
||||
str, "width: %g; ", node->getLayout().dimensions[YGDimensionWidth]);
|
||||
str, "width: %g; ", node->getLayout().dimension(YGDimensionWidth));
|
||||
appendFormattedString(
|
||||
str, "height: %g; ", node->getLayout().dimensions[YGDimensionHeight]);
|
||||
str, "height: %g; ", node->getLayout().dimension(YGDimensionHeight));
|
||||
appendFormattedString(
|
||||
str, "top: %g; ", node->getLayout().position[YGEdgeTop]);
|
||||
appendFormattedString(
|
||||
@@ -193,16 +193,16 @@ void nodeToString(
|
||||
appendNumberIfNotUndefined(str, "row-gap", style.gap()[YGGutterRow]);
|
||||
}
|
||||
|
||||
appendNumberIfNotAuto(str, "width", style.dimensions()[YGDimensionWidth]);
|
||||
appendNumberIfNotAuto(str, "height", style.dimensions()[YGDimensionHeight]);
|
||||
appendNumberIfNotAuto(str, "width", style.dimension(YGDimensionWidth));
|
||||
appendNumberIfNotAuto(str, "height", style.dimension(YGDimensionHeight));
|
||||
appendNumberIfNotAuto(
|
||||
str, "max-width", style.maxDimensions()[YGDimensionWidth]);
|
||||
str, "max-width", style.maxDimension(YGDimensionWidth));
|
||||
appendNumberIfNotAuto(
|
||||
str, "max-height", style.maxDimensions()[YGDimensionHeight]);
|
||||
str, "max-height", style.maxDimension(YGDimensionHeight));
|
||||
appendNumberIfNotAuto(
|
||||
str, "min-width", style.minDimensions()[YGDimensionWidth]);
|
||||
str, "min-width", style.minDimension(YGDimensionWidth));
|
||||
appendNumberIfNotAuto(
|
||||
str, "min-height", style.minDimensions()[YGDimensionHeight]);
|
||||
str, "min-height", style.minDimension(YGDimensionHeight));
|
||||
|
||||
if (style.positionType() != yoga::Node{}.getStyle().positionType()) {
|
||||
appendFormattedString(
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace facebook::yoga {
|
||||
|
||||
bool LayoutResults::operator==(LayoutResults layout) const {
|
||||
bool isEqual = yoga::inexactEquals(position, layout.position) &&
|
||||
yoga::inexactEquals(dimensions, layout.dimensions) &&
|
||||
yoga::inexactEquals(dimensions_, layout.dimensions_) &&
|
||||
yoga::inexactEquals(margin, layout.margin) &&
|
||||
yoga::inexactEquals(border, layout.border) &&
|
||||
yoga::inexactEquals(padding, layout.padding) &&
|
||||
@@ -30,15 +30,15 @@ bool LayoutResults::operator==(LayoutResults layout) const {
|
||||
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
||||
}
|
||||
|
||||
if (!yoga::isUndefined(measuredDimensions[0]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions[0])) {
|
||||
if (!yoga::isUndefined(measuredDimensions_[0]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions_[0])) {
|
||||
isEqual =
|
||||
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
|
||||
isEqual && (measuredDimensions_[0] == layout.measuredDimensions_[0]);
|
||||
}
|
||||
if (!yoga::isUndefined(measuredDimensions[1]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions[1])) {
|
||||
if (!yoga::isUndefined(measuredDimensions_[1]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions_[1])) {
|
||||
isEqual =
|
||||
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
|
||||
isEqual && (measuredDimensions_[1] == layout.measuredDimensions_[1]);
|
||||
}
|
||||
|
||||
return isEqual;
|
||||
|
||||
@@ -22,7 +22,6 @@ struct LayoutResults {
|
||||
static constexpr int32_t MaxCachedMeasurements = 8;
|
||||
|
||||
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 = {};
|
||||
@@ -31,6 +30,9 @@ struct LayoutResults {
|
||||
Direction direction_ : bitCount<Direction>() = Direction::Inherit;
|
||||
bool hadOverflow_ : 1 = false;
|
||||
|
||||
std::array<float, 2> dimensions_ = {{YGUndefined, YGUndefined}};
|
||||
std::array<float, 2> measuredDimensions_ = {{YGUndefined, YGUndefined}};
|
||||
|
||||
public:
|
||||
uint32_t computedFlexBasisGeneration = 0;
|
||||
FloatOptional computedFlexBasis = {};
|
||||
@@ -42,7 +44,6 @@ struct LayoutResults {
|
||||
|
||||
uint32_t nextCachedMeasurementsIndex = 0;
|
||||
std::array<CachedMeasurement, MaxCachedMeasurements> cachedMeasurements = {};
|
||||
std::array<float, 2> measuredDimensions = {{YGUndefined, YGUndefined}};
|
||||
|
||||
CachedMeasurement cachedLayout{};
|
||||
|
||||
@@ -57,10 +58,27 @@ struct LayoutResults {
|
||||
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);
|
||||
|
||||
@@ -340,8 +340,7 @@ void Node::setLayoutComputedFlexBasisGeneration(
|
||||
void Node::setLayoutMeasuredDimension(
|
||||
float measuredDimension,
|
||||
YGDimension dimension) {
|
||||
layout_.measuredDimensions[static_cast<size_t>(dimension)] =
|
||||
measuredDimension;
|
||||
layout_.setMeasuredDimension(dimension, measuredDimension);
|
||||
}
|
||||
|
||||
void Node::setLayoutHadOverflow(bool hadOverflow) {
|
||||
@@ -349,7 +348,7 @@ void Node::setLayoutHadOverflow(bool hadOverflow) {
|
||||
}
|
||||
|
||||
void Node::setLayoutDimension(float dimensionValue, YGDimension dimension) {
|
||||
layout_.dimensions[static_cast<size_t>(dimension)] = dimensionValue;
|
||||
layout_.setDimension(dimension, dimensionValue);
|
||||
}
|
||||
|
||||
// If both left and right are defined, then use left. Otherwise return +left or
|
||||
@@ -437,12 +436,11 @@ void Node::resolveDimension() {
|
||||
using namespace yoga;
|
||||
const Style& style = getStyle();
|
||||
for (auto dim : {YGDimensionWidth, YGDimensionHeight}) {
|
||||
if (!style.maxDimensions()[dim].isUndefined() &&
|
||||
yoga::inexactEquals(
|
||||
style.maxDimensions()[dim], style.minDimensions()[dim])) {
|
||||
resolvedDimensions_[dim] = style.maxDimensions()[dim];
|
||||
if (!style.maxDimension(dim).isUndefined() &&
|
||||
yoga::inexactEquals(style.maxDimension(dim), style.minDimension(dim))) {
|
||||
resolvedDimensions_[dim] = style.maxDimension(dim);
|
||||
} else {
|
||||
resolvedDimensions_[dim] = style.dimensions()[dim];
|
||||
resolvedDimensions_[dim] = style.dimension(dim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/numeric/FloatOptional.h>
|
||||
#include <yoga/style/CompactValue.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
@@ -61,6 +60,10 @@ inline bool inexactEquals(const double a, const double b) {
|
||||
return yoga::isUndefined(a) && yoga::isUndefined(b);
|
||||
}
|
||||
|
||||
inline bool inexactEquals(const FloatOptional a, const FloatOptional b) {
|
||||
return inexactEquals(a.unwrap(), b.unwrap());
|
||||
}
|
||||
|
||||
inline bool inexactEquals(const YGValue& a, const YGValue& b) {
|
||||
if (a.unit != b.unit) {
|
||||
return false;
|
||||
@@ -74,10 +77,6 @@ inline bool inexactEquals(const YGValue& a, const YGValue& b) {
|
||||
return fabs(a.value - b.value) < 0.0001f;
|
||||
}
|
||||
|
||||
inline bool inexactEquals(CompactValue a, CompactValue b) {
|
||||
return inexactEquals((YGValue)a, (YGValue)b);
|
||||
}
|
||||
|
||||
template <std::size_t Size, typename ElementT>
|
||||
bool inexactEquals(
|
||||
const std::array<ElementT, Size>& val1,
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <yoga/YGValue.h>
|
||||
|
||||
#include <yoga/bits/BitCast.h>
|
||||
#include <yoga/numeric/Comparison.h>
|
||||
|
||||
static_assert(
|
||||
std::numeric_limits<float>::is_iec559,
|
||||
@@ -176,4 +177,8 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
inline bool inexactEquals(CompactValue a, CompactValue b) {
|
||||
return inexactEquals((YGValue)a, (YGValue)b);
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <yoga/numeric/Comparison.h>
|
||||
#include <yoga/style/Style.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
bool operator==(const Style& lhs, const Style& rhs) {
|
||||
bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() &&
|
||||
lhs.flexDirection() == rhs.flexDirection() &&
|
||||
lhs.justifyContent() == rhs.justifyContent() &&
|
||||
lhs.alignContent() == rhs.alignContent() &&
|
||||
lhs.alignItems() == rhs.alignItems() &&
|
||||
lhs.alignSelf() == rhs.alignSelf() &&
|
||||
lhs.positionType() == rhs.positionType() &&
|
||||
lhs.flexWrap() == rhs.flexWrap() && lhs.overflow() == rhs.overflow() &&
|
||||
lhs.display() == rhs.display() &&
|
||||
yoga::inexactEquals(lhs.flexBasis(), rhs.flexBasis()) &&
|
||||
lhs.margin() == rhs.margin() && lhs.position() == rhs.position() &&
|
||||
lhs.padding() == rhs.padding() && lhs.border() == rhs.border() &&
|
||||
lhs.gap() == rhs.gap() && lhs.dimensions() == rhs.dimensions() &&
|
||||
lhs.minDimensions() == rhs.minDimensions() &&
|
||||
lhs.maxDimensions() == rhs.maxDimensions();
|
||||
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||
lhs.flex().isUndefined() == rhs.flex().isUndefined();
|
||||
if (areNonFloatValuesEqual && !lhs.flex().isUndefined() &&
|
||||
!rhs.flex().isUndefined()) {
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex() == rhs.flex();
|
||||
}
|
||||
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||
lhs.flexGrow().isUndefined() == rhs.flexGrow().isUndefined();
|
||||
if (areNonFloatValuesEqual && !lhs.flexGrow().isUndefined()) {
|
||||
areNonFloatValuesEqual =
|
||||
areNonFloatValuesEqual && lhs.flexGrow() == rhs.flexGrow();
|
||||
}
|
||||
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||
lhs.flexShrink().isUndefined() == rhs.flexShrink().isUndefined();
|
||||
if (areNonFloatValuesEqual && !rhs.flexShrink().isUndefined()) {
|
||||
areNonFloatValuesEqual =
|
||||
areNonFloatValuesEqual && lhs.flexShrink() == rhs.flexShrink();
|
||||
}
|
||||
|
||||
if (!(lhs.aspectRatio().isUndefined() && rhs.aspectRatio().isUndefined())) {
|
||||
areNonFloatValuesEqual =
|
||||
areNonFloatValuesEqual && lhs.aspectRatio() == rhs.aspectRatio();
|
||||
}
|
||||
|
||||
return areNonFloatValuesEqual;
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
||||
@@ -280,25 +280,25 @@ class YG_EXPORT Style {
|
||||
return {*this};
|
||||
}
|
||||
|
||||
const Dimensions& dimensions() const {
|
||||
return dimensions_;
|
||||
CompactValue dimension(YGDimension axis) const {
|
||||
return dimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::dimensions_> dimensions() {
|
||||
return {*this};
|
||||
void setDimension(YGDimension axis, CompactValue value) {
|
||||
dimensions_[axis] = value;
|
||||
}
|
||||
|
||||
const Dimensions& minDimensions() const {
|
||||
return minDimensions_;
|
||||
CompactValue minDimension(YGDimension axis) const {
|
||||
return minDimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::minDimensions_> minDimensions() {
|
||||
return {*this};
|
||||
void setMinDimension(YGDimension axis, CompactValue value) {
|
||||
minDimensions_[axis] = value;
|
||||
}
|
||||
|
||||
const Dimensions& maxDimensions() const {
|
||||
return maxDimensions_;
|
||||
CompactValue maxDimension(YGDimension axis) const {
|
||||
return maxDimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::maxDimensions_> maxDimensions() {
|
||||
return {*this};
|
||||
void setMaxDimension(YGDimension axis, CompactValue value) {
|
||||
maxDimensions_[axis] = value;
|
||||
}
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
@@ -308,10 +308,26 @@ class YG_EXPORT Style {
|
||||
Ref<FloatOptional, &Style::aspectRatio_> aspectRatio() {
|
||||
return {*this};
|
||||
}
|
||||
|
||||
bool operator==(const Style& other) const {
|
||||
return flags == other.flags && inexactEquals(flex_, other.flex_) &&
|
||||
inexactEquals(flexGrow_, other.flexGrow_) &&
|
||||
inexactEquals(flexShrink_, other.flexShrink_) &&
|
||||
inexactEquals(flexBasis_, other.flexBasis_) &&
|
||||
inexactEquals(margin_, other.margin_) &&
|
||||
inexactEquals(position_, other.position_) &&
|
||||
inexactEquals(padding_, other.padding_) &&
|
||||
inexactEquals(border_, other.border_) &&
|
||||
inexactEquals(gap_, other.gap_) &&
|
||||
inexactEquals(dimensions_, other.dimensions_) &&
|
||||
inexactEquals(minDimensions_, other.minDimensions_) &&
|
||||
inexactEquals(maxDimensions_, other.maxDimensions_) &&
|
||||
inexactEquals(aspectRatio_, other.aspectRatio_);
|
||||
}
|
||||
|
||||
bool operator!=(const Style& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
YG_EXPORT bool operator==(const Style& lhs, const Style& rhs);
|
||||
YG_EXPORT inline bool operator!=(const Style& lhs, const Style& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
} // namespace facebook::yoga
|
||||
|
||||
Reference in New Issue
Block a user