Moved YGNodeLeading position as a method on YGNode
Summary: Moved YGNodeLeading position as a method on YGNode Reviewed By: emilsjolander Differential Revision: D6682929 fbshipit-source-id: 3607aab1544b62b1126c5d75b2f6fb8f5ca2d45f
This commit is contained in:
committed by
Facebook Github Bot
parent
1eb9a5edd9
commit
0cfdb50477
@@ -9,6 +9,14 @@
|
|||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
YGFlexDirection YGFlexDirectionCross(
|
||||||
|
const YGFlexDirection flexDirection,
|
||||||
|
const YGDirection direction) {
|
||||||
|
return YGFlexDirectionIsColumn(flexDirection)
|
||||||
|
? YGResolveFlexDirection(YGFlexDirectionRow, direction)
|
||||||
|
: YGFlexDirectionColumn;
|
||||||
|
}
|
||||||
|
|
||||||
bool YGValueEqual(const YGValue a, const YGValue b) {
|
bool YGValueEqual(const YGValue a, const YGValue b) {
|
||||||
if (a.unit != b.unit) {
|
if (a.unit != b.unit) {
|
||||||
return false;
|
return false;
|
||||||
|
52
yoga/Utils.h
52
yoga/Utils.h
@@ -7,11 +7,61 @@
|
|||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "YGNode.h"
|
||||||
#include "Yoga-internal.h"
|
#include "Yoga-internal.h"
|
||||||
|
|
||||||
|
bool YGValueEqual(const YGValue a, const YGValue b);
|
||||||
|
|
||||||
|
YGFlexDirection YGFlexDirectionCross(
|
||||||
|
const YGFlexDirection flexDirection,
|
||||||
|
const YGDirection direction);
|
||||||
|
|
||||||
inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
|
inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
|
||||||
return flexDirection == YGFlexDirectionRow ||
|
return flexDirection == YGFlexDirectionRow ||
|
||||||
flexDirection == YGFlexDirectionRowReverse;
|
flexDirection == YGFlexDirectionRowReverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGValueEqual(const YGValue a, const YGValue b);
|
inline float YGResolveValue(const YGValue value, const float parentSize) {
|
||||||
|
switch (value.unit) {
|
||||||
|
case YGUnitUndefined:
|
||||||
|
case YGUnitAuto:
|
||||||
|
return YGUndefined;
|
||||||
|
case YGUnitPoint:
|
||||||
|
return value.value;
|
||||||
|
case YGUnitPercent:
|
||||||
|
return value.value * parentSize / 100.0f;
|
||||||
|
}
|
||||||
|
return YGUndefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool YGNodeIsLeadingPosDefined(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGFlexDirection axis) {
|
||||||
|
return (YGFlexDirectionIsRow(axis) &&
|
||||||
|
YGComputedEdgeValue(
|
||||||
|
node->getStyle().position, YGEdgeStart, &YGValueUndefined)
|
||||||
|
->unit != YGUnitUndefined) ||
|
||||||
|
YGComputedEdgeValue(
|
||||||
|
node->getStyle().position, leading[axis], &YGValueUndefined)
|
||||||
|
->unit != YGUnitUndefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) {
|
||||||
|
return flexDirection == YGFlexDirectionColumn ||
|
||||||
|
flexDirection == YGFlexDirectionColumnReverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline YGFlexDirection YGResolveFlexDirection(
|
||||||
|
const YGFlexDirection flexDirection,
|
||||||
|
const YGDirection direction) {
|
||||||
|
if (direction == YGDirectionRTL) {
|
||||||
|
if (flexDirection == YGFlexDirectionRow) {
|
||||||
|
return YGFlexDirectionRowReverse;
|
||||||
|
} else if (flexDirection == YGFlexDirectionRowReverse) {
|
||||||
|
return YGFlexDirectionRow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flexDirection;
|
||||||
|
}
|
||||||
|
@@ -82,6 +82,26 @@ YGValue YGNode::getResolvedDimension(int index) {
|
|||||||
std::array<YGValue, 2> YGNode::getResolvedDimensions() const {
|
std::array<YGValue, 2> YGNode::getResolvedDimensions() const {
|
||||||
return resolvedDimensions_;
|
return resolvedDimensions_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float YGNode::getLeadingPosition(
|
||||||
|
const YGFlexDirection axis,
|
||||||
|
const float axisSize) {
|
||||||
|
if (YGFlexDirectionIsRow(axis)) {
|
||||||
|
const YGValue* leadingPosition =
|
||||||
|
YGComputedEdgeValue(style_.position, YGEdgeStart, &YGValueUndefined);
|
||||||
|
if (leadingPosition->unit != YGUnitUndefined) {
|
||||||
|
return YGResolveValue(*leadingPosition, axisSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const YGValue* leadingPosition =
|
||||||
|
YGComputedEdgeValue(style_.position, leading[axis], &YGValueUndefined);
|
||||||
|
|
||||||
|
return leadingPosition->unit == YGUnitUndefined
|
||||||
|
? 0.0f
|
||||||
|
: YGResolveValue(*leadingPosition, axisSize);
|
||||||
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
|
||||||
void YGNode::setContext(void* context) {
|
void YGNode::setContext(void* context) {
|
||||||
|
@@ -76,6 +76,7 @@ struct YGNode {
|
|||||||
bool isDirty() const;
|
bool isDirty() const;
|
||||||
std::array<YGValue, 2> getResolvedDimensions() const;
|
std::array<YGValue, 2> getResolvedDimensions() const;
|
||||||
YGValue getResolvedDimension(int index);
|
YGValue getResolvedDimension(int index);
|
||||||
|
float getLeadingPosition(const YGFlexDirection axis, const float axisSize);
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
|
||||||
|
@@ -28,7 +28,6 @@ YG_EXTERN_C_END
|
|||||||
|
|
||||||
extern const std::array<YGEdge, 4> trailing;
|
extern const std::array<YGEdge, 4> trailing;
|
||||||
extern const std::array<YGEdge, 4> leading;
|
extern const std::array<YGEdge, 4> leading;
|
||||||
extern bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection);
|
|
||||||
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
||||||
extern const YGValue YGValueUndefined;
|
extern const YGValue YGValueUndefined;
|
||||||
extern const YGValue YGValueAuto;
|
extern const YGValue YGValueAuto;
|
||||||
|
@@ -151,21 +151,6 @@ const YGValue* YGComputedEdgeValue(
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float YGResolveValue(
|
|
||||||
const YGValue value,
|
|
||||||
const float parentSize) {
|
|
||||||
switch (value.unit) {
|
|
||||||
case YGUnitUndefined:
|
|
||||||
case YGUnitAuto:
|
|
||||||
return YGUndefined;
|
|
||||||
case YGUnitPoint:
|
|
||||||
return value.value;
|
|
||||||
case YGUnitPercent:
|
|
||||||
return value.value * parentSize / 100.0f;
|
|
||||||
}
|
|
||||||
return YGUndefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float YGResolveValueMargin(
|
static inline float YGResolveValueMargin(
|
||||||
const YGValue value,
|
const YGValue value,
|
||||||
const float parentSize) {
|
const float parentSize) {
|
||||||
@@ -782,10 +767,6 @@ static const std::array<YGEdge, 4> pos = {{
|
|||||||
static const std::array<YGDimension, 4> dim = {
|
static const std::array<YGDimension, 4> dim = {
|
||||||
{YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}};
|
{YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}};
|
||||||
|
|
||||||
static inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) {
|
|
||||||
return flexDirection == YGFlexDirectionColumn || flexDirection == YGFlexDirectionColumnReverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float YGNodeLeadingMargin(const YGNodeRef node,
|
static inline float YGNodeLeadingMargin(const YGNodeRef node,
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) {
|
const float widthSize) {
|
||||||
@@ -967,26 +948,6 @@ static float YGBaseline(const YGNodeRef node) {
|
|||||||
return baseline + baselineChild->getLayout().position[YGEdgeTop];
|
return baseline + baselineChild->getLayout().position[YGEdgeTop];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline YGFlexDirection YGResolveFlexDirection(const YGFlexDirection flexDirection,
|
|
||||||
const YGDirection direction) {
|
|
||||||
if (direction == YGDirectionRTL) {
|
|
||||||
if (flexDirection == YGFlexDirectionRow) {
|
|
||||||
return YGFlexDirectionRowReverse;
|
|
||||||
} else if (flexDirection == YGFlexDirectionRowReverse) {
|
|
||||||
return YGFlexDirectionRow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return flexDirection;
|
|
||||||
}
|
|
||||||
|
|
||||||
static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
|
|
||||||
const YGDirection direction) {
|
|
||||||
return YGFlexDirectionIsColumn(flexDirection)
|
|
||||||
? YGResolveFlexDirection(YGFlexDirectionRow, direction)
|
|
||||||
: YGFlexDirectionColumn;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool YGNodeIsFlex(const YGNodeRef node) {
|
static inline bool YGNodeIsFlex(const YGNodeRef node) {
|
||||||
return (
|
return (
|
||||||
node->getStyle().positionType == YGPositionTypeRelative &&
|
node->getStyle().positionType == YGPositionTypeRelative &&
|
||||||
@@ -1038,15 +999,6 @@ static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, const YGFlexDi
|
|||||||
return !YGFloatIsUndefined(value) && value >= 0.0f;
|
return !YGFloatIsUndefined(value) && value >= 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool YGNodeIsLeadingPosDefined(const YGNodeRef node, const YGFlexDirection axis) {
|
|
||||||
return (YGFlexDirectionIsRow(axis) &&
|
|
||||||
YGComputedEdgeValue(
|
|
||||||
node->getStyle().position, YGEdgeStart, &YGValueUndefined)
|
|
||||||
->unit != YGUnitUndefined) ||
|
|
||||||
YGComputedEdgeValue(
|
|
||||||
node->getStyle().position, leading[axis], &YGValueUndefined)
|
|
||||||
->unit != YGUnitUndefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool YGNodeIsTrailingPosDefined(const YGNodeRef node, const YGFlexDirection axis) {
|
static inline bool YGNodeIsTrailingPosDefined(const YGNodeRef node, const YGFlexDirection axis) {
|
||||||
return (YGFlexDirectionIsRow(axis) &&
|
return (YGFlexDirectionIsRow(axis) &&
|
||||||
@@ -1058,27 +1010,6 @@ static inline bool YGNodeIsTrailingPosDefined(const YGNodeRef node, const YGFlex
|
|||||||
->unit != YGUnitUndefined;
|
->unit != YGUnitUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float YGNodeLeadingPosition(const YGNodeRef node,
|
|
||||||
const YGFlexDirection axis,
|
|
||||||
const float axisSize) {
|
|
||||||
if (YGFlexDirectionIsRow(axis)) {
|
|
||||||
const YGValue* leadingPosition = YGComputedEdgeValue(
|
|
||||||
node->getStyle().position, YGEdgeStart, &YGValueUndefined);
|
|
||||||
if (leadingPosition->unit != YGUnitUndefined) {
|
|
||||||
return YGResolveValue(
|
|
||||||
*leadingPosition,
|
|
||||||
axisSize); // leadingPosition->resolveValue(axisSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const YGValue* leadingPosition = YGComputedEdgeValue(
|
|
||||||
node->getStyle().position, leading[axis], &YGValueUndefined);
|
|
||||||
|
|
||||||
return leadingPosition->unit == YGUnitUndefined
|
|
||||||
? 0.0f
|
|
||||||
: YGResolveValue(*leadingPosition, axisSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float YGNodeTrailingPosition(const YGNodeRef node,
|
static float YGNodeTrailingPosition(const YGNodeRef node,
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) {
|
const float axisSize) {
|
||||||
@@ -1157,8 +1088,9 @@ static void YGNodeSetChildTrailingPosition(const YGNodeRef node,
|
|||||||
static float YGNodeRelativePosition(const YGNodeRef node,
|
static float YGNodeRelativePosition(const YGNodeRef node,
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) {
|
const float axisSize) {
|
||||||
return YGNodeIsLeadingPosDefined(node, axis) ? YGNodeLeadingPosition(node, axis, axisSize)
|
return YGNodeIsLeadingPosDefined(node, axis)
|
||||||
: -YGNodeTrailingPosition(node, axis, axisSize);
|
? node->getLeadingPosition(axis, axisSize)
|
||||||
|
: -YGNodeTrailingPosition(node, axis, axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGConstrainMaxSizeForMode(const YGNodeRef node,
|
static void YGConstrainMaxSizeForMode(const YGNodeRef node,
|
||||||
@@ -1414,7 +1346,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
|
|||||||
childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] -
|
childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] -
|
||||||
(YGNodeLeadingBorder(node, YGFlexDirectionRow) +
|
(YGNodeLeadingBorder(node, YGFlexDirectionRow) +
|
||||||
YGNodeTrailingBorder(node, YGFlexDirectionRow)) -
|
YGNodeTrailingBorder(node, YGFlexDirectionRow)) -
|
||||||
(YGNodeLeadingPosition(child, YGFlexDirectionRow, width) +
|
(child->getLeadingPosition(YGFlexDirectionRow, width) +
|
||||||
YGNodeTrailingPosition(child, YGFlexDirectionRow, width));
|
YGNodeTrailingPosition(child, YGFlexDirectionRow, width));
|
||||||
childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width);
|
childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width);
|
||||||
}
|
}
|
||||||
@@ -1433,7 +1365,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
|
|||||||
childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] -
|
childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] -
|
||||||
(YGNodeLeadingBorder(node, YGFlexDirectionColumn) +
|
(YGNodeLeadingBorder(node, YGFlexDirectionColumn) +
|
||||||
YGNodeTrailingBorder(node, YGFlexDirectionColumn)) -
|
YGNodeTrailingBorder(node, YGFlexDirectionColumn)) -
|
||||||
(YGNodeLeadingPosition(child, YGFlexDirectionColumn, height) +
|
(child->getLeadingPosition(YGFlexDirectionColumn, height) +
|
||||||
YGNodeTrailingPosition(child, YGFlexDirectionColumn, height));
|
YGNodeTrailingPosition(child, YGFlexDirectionColumn, height));
|
||||||
childHeight = YGNodeBoundAxis(child, YGFlexDirectionColumn, childHeight, height, width);
|
childHeight = YGNodeBoundAxis(child, YGFlexDirectionColumn, childHeight, height, width);
|
||||||
}
|
}
|
||||||
@@ -2572,7 +2504,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
// defined, we override the position to whatever the user said
|
// defined, we override the position to whatever the user said
|
||||||
// (and margin/border).
|
// (and margin/border).
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
YGNodeLeadingPosition(child, mainAxis, availableInnerMainDim) +
|
child->getLeadingPosition(mainAxis, availableInnerMainDim) +
|
||||||
YGNodeLeadingBorder(node, mainAxis) +
|
YGNodeLeadingBorder(node, mainAxis) +
|
||||||
YGNodeLeadingMargin(child, mainAxis, availableInnerWidth),
|
YGNodeLeadingMargin(child, mainAxis, availableInnerWidth),
|
||||||
pos[mainAxis]);
|
pos[mainAxis]);
|
||||||
@@ -2664,8 +2596,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
const bool isChildLeadingPosDefined = YGNodeIsLeadingPosDefined(child, crossAxis);
|
const bool isChildLeadingPosDefined = YGNodeIsLeadingPosDefined(child, crossAxis);
|
||||||
if (isChildLeadingPosDefined) {
|
if (isChildLeadingPosDefined) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
YGNodeLeadingPosition(
|
child->getLeadingPosition(crossAxis, availableInnerCrossDim) +
|
||||||
child, crossAxis, availableInnerCrossDim) +
|
|
||||||
YGNodeLeadingBorder(node, crossAxis) +
|
YGNodeLeadingBorder(node, crossAxis) +
|
||||||
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth),
|
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth),
|
||||||
pos[crossAxis]);
|
pos[crossAxis]);
|
||||||
@@ -2948,10 +2879,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
case YGAlignBaseline: {
|
case YGAlignBaseline: {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
currentLead + maxAscentForCurrentLine - YGBaseline(child) +
|
currentLead + maxAscentForCurrentLine - YGBaseline(child) +
|
||||||
YGNodeLeadingPosition(
|
child->getLeadingPosition(
|
||||||
child,
|
YGFlexDirectionColumn, availableInnerCrossDim),
|
||||||
YGFlexDirectionColumn,
|
|
||||||
availableInnerCrossDim),
|
|
||||||
YGEdgeTop);
|
YGEdgeTop);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user