Moved setPosition as a method on YGNode
Summary: Moved setPosition as a method on YGNode Reviewed By: emilsjolander Differential Revision: D6683387 fbshipit-source-id: 83f64101faa700933771c69b222056ec2a6b8d1e
This commit is contained in:
committed by
Facebook Github Bot
parent
f2ba14c309
commit
76875af207
@@ -326,6 +326,46 @@ void YGNode::setLayoutDimension(float dimension, int index) {
|
|||||||
layout_.dimensions[index] = dimension;
|
layout_.dimensions[index] = dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If both left and right are defined, then use left. Otherwise return
|
||||||
|
// +left or -right depending on which is defined.
|
||||||
|
float YGNode::relativePosition(
|
||||||
|
const YGFlexDirection axis,
|
||||||
|
const float axisSize) {
|
||||||
|
return isLeadingPositionDefined(axis) ? getLeadingPosition(axis, axisSize)
|
||||||
|
: -getTrailingPosition(axis, axisSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGNode::setPosition(
|
||||||
|
const YGDirection direction,
|
||||||
|
const float mainSize,
|
||||||
|
const float crossSize,
|
||||||
|
const float parentWidth) {
|
||||||
|
/* Root nodes should be always layouted as LTR, so we don't return negative
|
||||||
|
* values. */
|
||||||
|
const YGDirection directionRespectingRoot =
|
||||||
|
parent_ != nullptr ? direction : YGDirectionLTR;
|
||||||
|
const YGFlexDirection mainAxis =
|
||||||
|
YGResolveFlexDirection(style_.flexDirection, directionRespectingRoot);
|
||||||
|
const YGFlexDirection crossAxis =
|
||||||
|
YGFlexDirectionCross(mainAxis, directionRespectingRoot);
|
||||||
|
|
||||||
|
const float relativePositionMain = relativePosition(mainAxis, mainSize);
|
||||||
|
const float relativePositionCross = relativePosition(crossAxis, crossSize);
|
||||||
|
|
||||||
|
setLayoutPosition(
|
||||||
|
getLeadingMargin(mainAxis, parentWidth) + relativePositionMain,
|
||||||
|
leading[mainAxis]);
|
||||||
|
setLayoutPosition(
|
||||||
|
getTrailingMargin(mainAxis, parentWidth) + relativePositionMain,
|
||||||
|
trailing[mainAxis]);
|
||||||
|
setLayoutPosition(
|
||||||
|
getLeadingMargin(crossAxis, parentWidth) + relativePositionCross,
|
||||||
|
leading[crossAxis]);
|
||||||
|
setLayoutPosition(
|
||||||
|
getTrailingMargin(crossAxis, parentWidth) + relativePositionCross,
|
||||||
|
trailing[crossAxis]);
|
||||||
|
}
|
||||||
|
|
||||||
YGNode::YGNode()
|
YGNode::YGNode()
|
||||||
: context_(nullptr),
|
: context_(nullptr),
|
||||||
print_(nullptr),
|
print_(nullptr),
|
||||||
|
@@ -31,6 +31,8 @@ struct YGNode {
|
|||||||
bool isDirty_;
|
bool isDirty_;
|
||||||
std::array<YGValue, 2> resolvedDimensions_;
|
std::array<YGValue, 2> resolvedDimensions_;
|
||||||
|
|
||||||
|
float relativePosition(const YGFlexDirection axis, const float axisSize);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YGNode();
|
YGNode();
|
||||||
~YGNode();
|
~YGNode();
|
||||||
@@ -110,6 +112,12 @@ struct YGNode {
|
|||||||
void setLayoutHadOverflow(bool hadOverflow);
|
void setLayoutHadOverflow(bool hadOverflow);
|
||||||
void setLayoutDimension(float dimension, int index);
|
void setLayoutDimension(float dimension, int index);
|
||||||
|
|
||||||
|
void setPosition(
|
||||||
|
const YGDirection direction,
|
||||||
|
const float mainSize,
|
||||||
|
const float crossSize,
|
||||||
|
const float parentWidth);
|
||||||
|
|
||||||
// Other methods
|
// Other methods
|
||||||
YGValue marginLeadingValue(const YGFlexDirection axis) const;
|
YGValue marginLeadingValue(const YGFlexDirection axis) const;
|
||||||
YGValue marginTrailingValue(const YGFlexDirection axis) const;
|
YGValue marginTrailingValue(const YGFlexDirection axis) const;
|
||||||
|
@@ -1020,16 +1020,6 @@ static void YGNodeSetChildTrailingPosition(const YGNodeRef node,
|
|||||||
trailing[axis]);
|
trailing[axis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If both left and right are defined, then use left. Otherwise return
|
|
||||||
// +left or -right depending on which is defined.
|
|
||||||
static float YGNodeRelativePosition(const YGNodeRef node,
|
|
||||||
const YGFlexDirection axis,
|
|
||||||
const float axisSize) {
|
|
||||||
return node->isLeadingPositionDefined(axis)
|
|
||||||
? node->getLeadingPosition(axis, axisSize)
|
|
||||||
: -node->getTrailingPosition(axis, axisSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void YGConstrainMaxSizeForMode(const YGNodeRef node,
|
static void YGConstrainMaxSizeForMode(const YGNodeRef node,
|
||||||
const enum YGFlexDirection axis,
|
const enum YGFlexDirection axis,
|
||||||
const float parentAxisSize,
|
const float parentAxisSize,
|
||||||
@@ -1054,35 +1044,6 @@ static void YGConstrainMaxSizeForMode(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGNodeSetPosition(const YGNodeRef node,
|
|
||||||
const YGDirection direction,
|
|
||||||
const float mainSize,
|
|
||||||
const float crossSize,
|
|
||||||
const float parentWidth) {
|
|
||||||
/* Root nodes should be always layouted as LTR, so we don't return negative values. */
|
|
||||||
const YGDirection directionRespectingRoot =
|
|
||||||
node->getParent() != nullptr ? direction : YGDirectionLTR;
|
|
||||||
const YGFlexDirection mainAxis = YGResolveFlexDirection(
|
|
||||||
node->getStyle().flexDirection, directionRespectingRoot);
|
|
||||||
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot);
|
|
||||||
|
|
||||||
const float relativePositionMain = YGNodeRelativePosition(node, mainAxis, mainSize);
|
|
||||||
const float relativePositionCross = YGNodeRelativePosition(node, crossAxis, crossSize);
|
|
||||||
|
|
||||||
node->setLayoutPosition(
|
|
||||||
node->getLeadingMargin(mainAxis, parentWidth) + relativePositionMain,
|
|
||||||
leading[mainAxis]);
|
|
||||||
node->setLayoutPosition(
|
|
||||||
node->getTrailingMargin(mainAxis, parentWidth) + relativePositionMain,
|
|
||||||
trailing[mainAxis]);
|
|
||||||
node->setLayoutPosition(
|
|
||||||
node->getLeadingMargin(crossAxis, parentWidth) + relativePositionCross,
|
|
||||||
leading[crossAxis]);
|
|
||||||
node->setLayoutPosition(
|
|
||||||
node->getTrailingMargin(crossAxis, parentWidth) + relativePositionCross,
|
|
||||||
trailing[crossAxis]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
|
static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
|
||||||
const YGNodeRef child,
|
const YGNodeRef child,
|
||||||
const float width,
|
const float width,
|
||||||
@@ -1887,11 +1848,11 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
if (performLayout) {
|
if (performLayout) {
|
||||||
// Set the initial position (relative to the parent).
|
// Set the initial position (relative to the parent).
|
||||||
const YGDirection childDirection = YGNodeResolveDirection(child, direction);
|
const YGDirection childDirection = YGNodeResolveDirection(child, direction);
|
||||||
YGNodeSetPosition(child,
|
child->setPosition(
|
||||||
childDirection,
|
childDirection,
|
||||||
availableInnerMainDim,
|
availableInnerMainDim,
|
||||||
availableInnerCrossDim,
|
availableInnerCrossDim,
|
||||||
availableInnerWidth);
|
availableInnerWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Absolute-positioned children don't participate in flex layout. Add them
|
// Absolute-positioned children don't participate in flex layout. Add them
|
||||||
@@ -3477,12 +3438,8 @@ void YGNodeCalculateLayout(const YGNodeRef node,
|
|||||||
true,
|
true,
|
||||||
"initial",
|
"initial",
|
||||||
node->getConfig())) {
|
node->getConfig())) {
|
||||||
YGNodeSetPosition(
|
node->setPosition(
|
||||||
node,
|
node->getLayout().direction, parentWidth, parentHeight, parentWidth);
|
||||||
node->getLayout().direction,
|
|
||||||
parentWidth,
|
|
||||||
parentHeight,
|
|
||||||
parentWidth);
|
|
||||||
YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f);
|
YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f);
|
||||||
|
|
||||||
if (gPrintTree) {
|
if (gPrintTree) {
|
||||||
|
Reference in New Issue
Block a user