Rename YogaNode.parent -> YogaNode.owner
Summary: In the persistent version of Yoga, a YogaNode can be shared between two YogaTrees, that means that a YogaNode could have more than one Parent at one point in time. That's why the concept of Parent of a YogaNode is not a 1-1 relationship anymore. This diff changes the semantic of Parent of a YogaNode to Owner of a Yoga Node. CC sebmarkbage and priteshrnandgaonkar for more context. Technically this diff renames the field YogaNode.parent to YogaNode.owner (and every internal field, Getter and Setter that is related to parent) Note that as part of this diff I also modified the CSSLayoutDEPRECATED version of Yoga in order to keep compatibility with the C++ implementation. Reviewed By: priteshrnandgaonkar Differential Revision: D7352778 fbshipit-source-id: dcf1af5e72bfc3063b5c4bda197d7952a9194768
This commit is contained in:
committed by
Facebook Github Bot
parent
17901ea5c2
commit
f0edefdbb7
@@ -46,14 +46,14 @@ import java.util.Map;
|
|||||||
* <YogaLayout
|
* <YogaLayout
|
||||||
* xmlns:android="http://schemas.android.com/apk/res/android"
|
* xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
* xmlns:yoga="http://schemas.android.com/apk/com.facebook.yoga.android"
|
* xmlns:yoga="http://schemas.android.com/apk/com.facebook.yoga.android"
|
||||||
* android:layout_width="match_parent"
|
* android:layout_width="match_owner"
|
||||||
* android:layout_height="match_parent"
|
* android:layout_height="match_owner"
|
||||||
* yoga:flex_direction="row"
|
* yoga:flex_direction="row"
|
||||||
* yoga:padding_all="10dp"
|
* yoga:padding_all="10dp"
|
||||||
* >
|
* >
|
||||||
* <TextView
|
* <TextView
|
||||||
* android:layout_width="match_parent"
|
* android:layout_width="match_owner"
|
||||||
* android:layout_height="match_parent"
|
* android:layout_height="match_owner"
|
||||||
* android:text="Hello, World!"
|
* android:text="Hello, World!"
|
||||||
* yoga:flex="1"
|
* yoga:flex="1"
|
||||||
* />
|
* />
|
||||||
@@ -262,11 +262,11 @@ public class YogaLayout extends ViewGroup {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final YogaNode parent = node.getParent();
|
final YogaNode owner = node.getOwner();
|
||||||
|
|
||||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
for (int i = 0; i < owner.getChildCount(); i++) {
|
||||||
if (parent.getChildAt(i).equals(node)) {
|
if (owner.getChildAt(i).equals(node)) {
|
||||||
parent.removeChildAt(i);
|
owner.removeChildAt(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,7 +315,7 @@ public class YogaLayout extends ViewGroup {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
// Either we are a root of a tree, or this function is called by our parent's onLayout, in which
|
// Either we are a root of a tree, or this function is called by our owner's onLayout, in which
|
||||||
// case our r-l and b-t are the size of our node.
|
// case our r-l and b-t are the size of our node.
|
||||||
if (!(getParent() instanceof YogaLayout)) {
|
if (!(getParent() instanceof YogaLayout)) {
|
||||||
createLayout(
|
createLayout(
|
||||||
@@ -699,7 +699,7 @@ public class YogaLayout extends ViewGroup {
|
|||||||
/**
|
/**
|
||||||
* Constructs a set of layout params, given width and height specs. In this case, we can set
|
* Constructs a set of layout params, given width and height specs. In this case, we can set
|
||||||
* the {@code yoga:width} and {@code yoga:height} if we are given them explicitly. If other
|
* the {@code yoga:width} and {@code yoga:height} if we are given them explicitly. If other
|
||||||
* options (such as {@code match_parent} or {@code wrap_content} are given, then the parent
|
* options (such as {@code match_owner} or {@code wrap_content} are given, then the owner
|
||||||
* LayoutParams will store them, and we deal with them during layout. (see
|
* LayoutParams will store them, and we deal with them during layout. (see
|
||||||
* {@link YogaLayout#createLayout})
|
* {@link YogaLayout#createLayout})
|
||||||
*
|
*
|
||||||
@@ -773,9 +773,9 @@ public class YogaLayout extends ViewGroup {
|
|||||||
* {@code View}'s measure function.
|
* {@code View}'s measure function.
|
||||||
*
|
*
|
||||||
* @param node The yoga node to measure
|
* @param node The yoga node to measure
|
||||||
* @param width The suggested width from the parent
|
* @param width The suggested width from the owner
|
||||||
* @param widthMode The type of suggestion for the width
|
* @param widthMode The type of suggestion for the width
|
||||||
* @param height The suggested height from the parent
|
* @param height The suggested height from the owner
|
||||||
* @param heightMode The type of suggestion for the height
|
* @param heightMode The type of suggestion for the height
|
||||||
* @return A measurement output ({@code YogaMeasureOutput}) for the node
|
* @return A measurement output ({@code YogaMeasureOutput}) for the node
|
||||||
*/
|
*/
|
||||||
|
@@ -29,7 +29,7 @@ public class YogaNode implements Cloneable {
|
|||||||
*/
|
*/
|
||||||
static native int jni_YGNodeGetInstanceCount();
|
static native int jni_YGNodeGetInstanceCount();
|
||||||
|
|
||||||
private YogaNode mParent;
|
private YogaNode mOwner;
|
||||||
private List<YogaNode> mChildren;
|
private List<YogaNode> mChildren;
|
||||||
private YogaMeasureFunction mMeasureFunction;
|
private YogaMeasureFunction mMeasureFunction;
|
||||||
private YogaBaselineFunction mBaselineFunction;
|
private YogaBaselineFunction mBaselineFunction;
|
||||||
@@ -152,7 +152,7 @@ public class YogaNode implements Cloneable {
|
|||||||
|
|
||||||
private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
||||||
public void addChildAt(YogaNode child, int i) {
|
public void addChildAt(YogaNode child, int i) {
|
||||||
if (child.mParent != null) {
|
if (child.mOwner != null) {
|
||||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ public class YogaNode implements Cloneable {
|
|||||||
mChildren = new ArrayList<>(4);
|
mChildren = new ArrayList<>(4);
|
||||||
}
|
}
|
||||||
mChildren.add(i, child);
|
mChildren.add(i, child);
|
||||||
child.mParent = this;
|
child.mOwner = this;
|
||||||
jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,15 +180,23 @@ public class YogaNode implements Cloneable {
|
|||||||
public YogaNode removeChildAt(int i) {
|
public YogaNode removeChildAt(int i) {
|
||||||
|
|
||||||
final YogaNode child = mChildren.remove(i);
|
final YogaNode child = mChildren.remove(i);
|
||||||
child.mParent = null;
|
child.mOwner = null;
|
||||||
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
|
||||||
|
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
|
||||||
|
* to.
|
||||||
|
* This method will return the parent of the {@link YogaNode} when the
|
||||||
|
* {@link YogaNode} only belongs to one YogaTree or null when the
|
||||||
|
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public
|
public
|
||||||
YogaNode getParent() {
|
YogaNode getOwner() {
|
||||||
return mParent;
|
return mOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int indexOf(YogaNode child) {
|
public int indexOf(YogaNode child) {
|
||||||
|
@@ -152,7 +152,7 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
|
|||||||
|
|
||||||
static YGNodeRef YGJNIOnNodeClonedFunc(
|
static YGNodeRef YGJNIOnNodeClonedFunc(
|
||||||
YGNodeRef oldNode,
|
YGNodeRef oldNode,
|
||||||
YGNodeRef parent,
|
YGNodeRef owner,
|
||||||
int childIndex) {
|
int childIndex) {
|
||||||
auto config = oldNode->getConfig();
|
auto config = oldNode->getConfig();
|
||||||
if (!config) {
|
if (!config) {
|
||||||
@@ -171,7 +171,7 @@ static YGNodeRef YGJNIOnNodeClonedFunc(
|
|||||||
auto newNode = onNodeClonedFunc(
|
auto newNode = onNodeClonedFunc(
|
||||||
javaConfig->get(),
|
javaConfig->get(),
|
||||||
YGNodeJobject(oldNode)->lockLocal(),
|
YGNodeJobject(oldNode)->lockLocal(),
|
||||||
YGNodeJobject(parent)->lockLocal(),
|
YGNodeJobject(owner)->lockLocal(),
|
||||||
childIndex);
|
childIndex);
|
||||||
|
|
||||||
static auto replaceChild = findClassStatic("com/facebook/yoga/YogaNode")
|
static auto replaceChild = findClassStatic("com/facebook/yoga/YogaNode")
|
||||||
@@ -180,7 +180,7 @@ static YGNodeRef YGJNIOnNodeClonedFunc(
|
|||||||
jint)>("replaceChild");
|
jint)>("replaceChild");
|
||||||
|
|
||||||
jlong newNodeNativePointer = replaceChild(
|
jlong newNodeNativePointer = replaceChild(
|
||||||
YGNodeJobject(parent)->lockLocal(),
|
YGNodeJobject(owner)->lockLocal(),
|
||||||
newNode,
|
newNode,
|
||||||
childIndex);
|
childIndex);
|
||||||
|
|
||||||
|
@@ -258,7 +258,7 @@ public class YogaNodeTest {
|
|||||||
config.setOnCloneNode(
|
config.setOnCloneNode(
|
||||||
new YogaNodeCloneFunction() {
|
new YogaNodeCloneFunction() {
|
||||||
@Override
|
@Override
|
||||||
public YogaNode cloneNode(YogaNode oldNode, YogaNode parent, int childIndex) {
|
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) {
|
||||||
try {
|
try {
|
||||||
onNodeClonedExecuted.set(true);
|
onNodeClonedExecuted.set(true);
|
||||||
return oldNode.clone();
|
return oldNode.clone();
|
||||||
@@ -295,7 +295,7 @@ public class YogaNodeTest {
|
|||||||
config.setOnCloneNode(
|
config.setOnCloneNode(
|
||||||
new YogaNodeCloneFunction() {
|
new YogaNodeCloneFunction() {
|
||||||
@Override
|
@Override
|
||||||
public YogaNode cloneNode(YogaNode oldNode, YogaNode parent, int childIndex) {
|
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) {
|
||||||
try {
|
try {
|
||||||
return oldNode.clone();
|
return oldNode.clone();
|
||||||
} catch (CloneNotSupportedException ex) {
|
} catch (CloneNotSupportedException ex) {
|
||||||
|
@@ -30,9 +30,9 @@ TEST(YogaTest, set_children_adds_children_to_parent) {
|
|||||||
const std::vector<YGNodeRef> expectedChildren = {root_child0, root_child1};
|
const std::vector<YGNodeRef> expectedChildren = {root_child0, root_child1};
|
||||||
ASSERT_EQ(children, expectedChildren);
|
ASSERT_EQ(children, expectedChildren);
|
||||||
|
|
||||||
const std::vector<YGNodeRef> parents = {YGNodeGetParent(root_child0), YGNodeGetParent(root_child1)};
|
const std::vector<YGNodeRef> owners = {YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)};
|
||||||
const std::vector<YGNodeRef> expectedParents = {root, root};
|
const std::vector<YGNodeRef> expectedOwners = {root, root};
|
||||||
ASSERT_EQ(parents, expectedParents);
|
ASSERT_EQ(owners, expectedOwners);
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
@@ -49,9 +49,9 @@ TEST(YogaTest, set_children_to_empty_removes_old_children) {
|
|||||||
const std::vector<YGNodeRef> expectedChildren = {};
|
const std::vector<YGNodeRef> expectedChildren = {};
|
||||||
ASSERT_EQ(children, expectedChildren);
|
ASSERT_EQ(children, expectedChildren);
|
||||||
|
|
||||||
const std::vector<YGNodeRef> parents = {YGNodeGetParent(root_child0), YGNodeGetParent(root_child1)};
|
const std::vector<YGNodeRef> owners = {YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)};
|
||||||
const std::vector<YGNodeRef> expectedParents = {nullptr, nullptr};
|
const std::vector<YGNodeRef> expectedOwners = {nullptr, nullptr};
|
||||||
ASSERT_EQ(parents, expectedParents);
|
ASSERT_EQ(owners, expectedOwners);
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
@@ -72,9 +72,9 @@ TEST(YogaTest, set_children_replaces_non_common_children) {
|
|||||||
const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child3};
|
const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child3};
|
||||||
ASSERT_EQ(children, expectedChildren);
|
ASSERT_EQ(children, expectedChildren);
|
||||||
|
|
||||||
const std::vector<YGNodeRef> parents = {YGNodeGetParent(root_child0), YGNodeGetParent(root_child1)};
|
const std::vector<YGNodeRef> owners = {YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)};
|
||||||
const std::vector<YGNodeRef> expectedParents = {nullptr, nullptr};
|
const std::vector<YGNodeRef> expectedOwners = {nullptr, nullptr};
|
||||||
ASSERT_EQ(parents, expectedParents);
|
ASSERT_EQ(owners, expectedOwners);
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
YGNodeFree(root_child0);
|
YGNodeFree(root_child0);
|
||||||
@@ -97,14 +97,14 @@ TEST(YogaTest, set_children_keeps_and_reorders_common_children) {
|
|||||||
const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child1, root_child3};
|
const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child1, root_child3};
|
||||||
ASSERT_EQ(children, expectedChildren);
|
ASSERT_EQ(children, expectedChildren);
|
||||||
|
|
||||||
const std::vector<YGNodeRef> parents = {
|
const std::vector<YGNodeRef> owners = {
|
||||||
YGNodeGetParent(root_child0),
|
YGNodeGetOwner(root_child0),
|
||||||
YGNodeGetParent(root_child1),
|
YGNodeGetOwner(root_child1),
|
||||||
YGNodeGetParent(root_child2),
|
YGNodeGetOwner(root_child2),
|
||||||
YGNodeGetParent(root_child3)
|
YGNodeGetOwner(root_child3)
|
||||||
};
|
};
|
||||||
const std::vector<YGNodeRef> expectedParents = {nullptr, root, root, root};
|
const std::vector<YGNodeRef> expectedOwners = {nullptr, root, root, root};
|
||||||
ASSERT_EQ(parents, expectedParents);
|
ASSERT_EQ(owners, expectedOwners);
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
YGNodeFree(root_child0);
|
YGNodeFree(root_child0);
|
||||||
|
10
yoga/Utils.h
10
yoga/Utils.h
@@ -45,7 +45,7 @@ struct YGCollectFlexItemsRowValues {
|
|||||||
float remainingFreeSpace;
|
float remainingFreeSpace;
|
||||||
// The size of the mainDim for the row after considering size, padding, margin
|
// The size of the mainDim for the row after considering size, padding, margin
|
||||||
// and border of flex items. This is used to calculate maxLineDim after going
|
// and border of flex items. This is used to calculate maxLineDim after going
|
||||||
// through all the rows to decide on the main axis size of parent.
|
// through all the rows to decide on the main axis size of owner.
|
||||||
float mainDim;
|
float mainDim;
|
||||||
// The size of the crossDim for the row after considering size, padding,
|
// The size of the crossDim for the row after considering size, padding,
|
||||||
// margin and border of flex items. Used for calculating containers crossSize.
|
// margin and border of flex items. Used for calculating containers crossSize.
|
||||||
@@ -109,7 +109,7 @@ inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
|
|||||||
flexDirection == YGFlexDirectionRowReverse;
|
flexDirection == YGFlexDirectionRowReverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline YGFloatOptional YGResolveValue(const YGValue value, const float parentSize) {
|
inline YGFloatOptional YGResolveValue(const YGValue value, const float ownerSize) {
|
||||||
switch (value.unit) {
|
switch (value.unit) {
|
||||||
case YGUnitUndefined:
|
case YGUnitUndefined:
|
||||||
case YGUnitAuto:
|
case YGUnitAuto:
|
||||||
@@ -118,7 +118,7 @@ inline YGFloatOptional YGResolveValue(const YGValue value, const float parentSiz
|
|||||||
return YGFloatOptional(value.value);
|
return YGFloatOptional(value.value);
|
||||||
case YGUnitPercent:
|
case YGUnitPercent:
|
||||||
return YGFloatOptional(
|
return YGFloatOptional(
|
||||||
static_cast<float>(value.value * parentSize * 0.01));
|
static_cast<float>(value.value * ownerSize * 0.01));
|
||||||
}
|
}
|
||||||
return YGFloatOptional();
|
return YGFloatOptional();
|
||||||
}
|
}
|
||||||
@@ -144,6 +144,6 @@ inline YGFlexDirection YGResolveFlexDirection(
|
|||||||
|
|
||||||
static inline float YGResolveValueMargin(
|
static inline float YGResolveValueMargin(
|
||||||
const YGValue value,
|
const YGValue value,
|
||||||
const float parentSize) {
|
const float ownerSize) {
|
||||||
return value.unit == YGUnitAuto ? 0 : YGUnwrapFloatOptional(YGResolveValue(value, parentSize));
|
return value.unit == YGUnitAuto ? 0 : YGUnwrapFloatOptional(YGResolveValue(value, ownerSize));
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ YGLayout::YGLayout()
|
|||||||
computedFlexBasis(YGUndefined),
|
computedFlexBasis(YGUndefined),
|
||||||
hadOverflow(false),
|
hadOverflow(false),
|
||||||
generationCount(0),
|
generationCount(0),
|
||||||
lastParentDirection((YGDirection)-1),
|
lastOwnerDirection((YGDirection)-1),
|
||||||
nextCachedMeasurementsIndex(0),
|
nextCachedMeasurementsIndex(0),
|
||||||
cachedMeasurements(),
|
cachedMeasurements(),
|
||||||
measuredDimensions(kYGDefaultDimensionValues),
|
measuredDimensions(kYGDefaultDimensionValues),
|
||||||
@@ -37,7 +37,7 @@ bool YGLayout::operator==(YGLayout layout) const {
|
|||||||
YGFloatArrayEqual(border, layout.border) &&
|
YGFloatArrayEqual(border, layout.border) &&
|
||||||
YGFloatArrayEqual(padding, layout.padding) &&
|
YGFloatArrayEqual(padding, layout.padding) &&
|
||||||
direction == layout.direction && hadOverflow == layout.hadOverflow &&
|
direction == layout.direction && hadOverflow == layout.hadOverflow &&
|
||||||
lastParentDirection == layout.lastParentDirection &&
|
lastOwnerDirection == layout.lastOwnerDirection &&
|
||||||
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
|
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
|
||||||
cachedLayout == layout.cachedLayout;
|
cachedLayout == layout.cachedLayout;
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ struct YGLayout {
|
|||||||
// Instead of recomputing the entire layout every single time, we
|
// Instead of recomputing the entire layout every single time, we
|
||||||
// cache some information to break early when nothing changed
|
// cache some information to break early when nothing changed
|
||||||
uint32_t generationCount;
|
uint32_t generationCount;
|
||||||
YGDirection lastParentDirection;
|
YGDirection lastOwnerDirection;
|
||||||
|
|
||||||
uint32_t nextCachedMeasurementsIndex;
|
uint32_t nextCachedMeasurementsIndex;
|
||||||
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
|
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
|
||||||
|
@@ -49,8 +49,8 @@ uint32_t YGNode::getLineIndex() const {
|
|||||||
return lineIndex_;
|
return lineIndex_;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef YGNode::getParent() const {
|
YGNodeRef YGNode::getOwner() const {
|
||||||
return parent_;
|
return owner_;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGVector YGNode::getChildren() const {
|
YGVector YGNode::getChildren() const {
|
||||||
@@ -237,8 +237,8 @@ void YGNode::setLineIndex(uint32_t lineIndex) {
|
|||||||
lineIndex_ = lineIndex;
|
lineIndex_ = lineIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::setParent(YGNodeRef parent) {
|
void YGNode::setOwner(YGNodeRef owner) {
|
||||||
parent_ = parent;
|
owner_ = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::setChildren(const YGVector& children) {
|
void YGNode::setChildren(const YGVector& children) {
|
||||||
@@ -305,8 +305,8 @@ void YGNode::setLayoutPadding(float padding, int index) {
|
|||||||
layout_.padding[index] = padding;
|
layout_.padding[index] = padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::setLayoutLastParentDirection(YGDirection direction) {
|
void YGNode::setLayoutLastOwnerDirection(YGDirection direction) {
|
||||||
layout_.lastParentDirection = direction;
|
layout_.lastOwnerDirection = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::setLayoutComputedFlexBasis(float computedFlexBasis) {
|
void YGNode::setLayoutComputedFlexBasis(float computedFlexBasis) {
|
||||||
@@ -347,11 +347,11 @@ void YGNode::setPosition(
|
|||||||
const YGDirection direction,
|
const YGDirection direction,
|
||||||
const float mainSize,
|
const float mainSize,
|
||||||
const float crossSize,
|
const float crossSize,
|
||||||
const float parentWidth) {
|
const float ownerWidth) {
|
||||||
/* Root nodes should be always layouted as LTR, so we don't return negative
|
/* Root nodes should be always layouted as LTR, so we don't return negative
|
||||||
* values. */
|
* values. */
|
||||||
const YGDirection directionRespectingRoot =
|
const YGDirection directionRespectingRoot =
|
||||||
parent_ != nullptr ? direction : YGDirectionLTR;
|
owner_ != nullptr ? direction : YGDirectionLTR;
|
||||||
const YGFlexDirection mainAxis =
|
const YGFlexDirection mainAxis =
|
||||||
YGResolveFlexDirection(style_.flexDirection, directionRespectingRoot);
|
YGResolveFlexDirection(style_.flexDirection, directionRespectingRoot);
|
||||||
const YGFlexDirection crossAxis =
|
const YGFlexDirection crossAxis =
|
||||||
@@ -361,16 +361,16 @@ void YGNode::setPosition(
|
|||||||
const float relativePositionCross = relativePosition(crossAxis, crossSize);
|
const float relativePositionCross = relativePosition(crossAxis, crossSize);
|
||||||
|
|
||||||
setLayoutPosition(
|
setLayoutPosition(
|
||||||
getLeadingMargin(mainAxis, parentWidth) + relativePositionMain,
|
getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain,
|
||||||
leading[mainAxis]);
|
leading[mainAxis]);
|
||||||
setLayoutPosition(
|
setLayoutPosition(
|
||||||
getTrailingMargin(mainAxis, parentWidth) + relativePositionMain,
|
getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain,
|
||||||
trailing[mainAxis]);
|
trailing[mainAxis]);
|
||||||
setLayoutPosition(
|
setLayoutPosition(
|
||||||
getLeadingMargin(crossAxis, parentWidth) + relativePositionCross,
|
getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross,
|
||||||
leading[crossAxis]);
|
leading[crossAxis]);
|
||||||
setLayoutPosition(
|
setLayoutPosition(
|
||||||
getTrailingMargin(crossAxis, parentWidth) + relativePositionCross,
|
getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross,
|
||||||
trailing[crossAxis]);
|
trailing[crossAxis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +385,7 @@ YGNode::YGNode()
|
|||||||
style_(YGStyle()),
|
style_(YGStyle()),
|
||||||
layout_(YGLayout()),
|
layout_(YGLayout()),
|
||||||
lineIndex_(0),
|
lineIndex_(0),
|
||||||
parent_(nullptr),
|
owner_(nullptr),
|
||||||
children_(YGVector()),
|
children_(YGVector()),
|
||||||
nextChild_(nullptr),
|
nextChild_(nullptr),
|
||||||
config_(nullptr),
|
config_(nullptr),
|
||||||
@@ -403,7 +403,7 @@ YGNode::YGNode(const YGNode& node)
|
|||||||
style_(node.style_),
|
style_(node.style_),
|
||||||
layout_(node.layout_),
|
layout_(node.layout_),
|
||||||
lineIndex_(node.lineIndex_),
|
lineIndex_(node.lineIndex_),
|
||||||
parent_(node.parent_),
|
owner_(node.owner_),
|
||||||
children_(node.children_),
|
children_(node.children_),
|
||||||
nextChild_(node.nextChild_),
|
nextChild_(node.nextChild_),
|
||||||
config_(node.config_),
|
config_(node.config_),
|
||||||
@@ -425,7 +425,7 @@ YGNode::YGNode(
|
|||||||
YGStyle style,
|
YGStyle style,
|
||||||
const YGLayout& layout,
|
const YGLayout& layout,
|
||||||
uint32_t lineIndex,
|
uint32_t lineIndex,
|
||||||
YGNodeRef parent,
|
YGNodeRef owner,
|
||||||
const YGVector& children,
|
const YGVector& children,
|
||||||
YGNodeRef nextChild,
|
YGNodeRef nextChild,
|
||||||
YGConfigRef config,
|
YGConfigRef config,
|
||||||
@@ -441,7 +441,7 @@ YGNode::YGNode(
|
|||||||
style_(style),
|
style_(style),
|
||||||
layout_(layout),
|
layout_(layout),
|
||||||
lineIndex_(lineIndex),
|
lineIndex_(lineIndex),
|
||||||
parent_(parent),
|
owner_(owner),
|
||||||
children_(children),
|
children_(children),
|
||||||
nextChild_(nextChild),
|
nextChild_(nextChild),
|
||||||
config_(config),
|
config_(config),
|
||||||
@@ -467,7 +467,7 @@ YGNode& YGNode::operator=(const YGNode& node) {
|
|||||||
style_ = node.style_;
|
style_ = node.style_;
|
||||||
layout_ = node.layout_;
|
layout_ = node.layout_;
|
||||||
lineIndex_ = node.getLineIndex();
|
lineIndex_ = node.getLineIndex();
|
||||||
parent_ = node.getParent();
|
owner_ = node.getOwner();
|
||||||
children_ = node.getChildren();
|
children_ = node.getChildren();
|
||||||
nextChild_ = node.getNextChild();
|
nextChild_ = node.getNextChild();
|
||||||
config_ = node.getConfig();
|
config_ = node.getConfig();
|
||||||
@@ -518,9 +518,9 @@ void YGNode::resolveDimension() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGDirection YGNode::resolveDirection(const YGDirection parentDirection) {
|
YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) {
|
||||||
if (style_.direction == YGDirectionInherit) {
|
if (style_.direction == YGDirectionInherit) {
|
||||||
return parentDirection > YGDirectionInherit ? parentDirection
|
return ownerDirection > YGDirectionInherit ? ownerDirection
|
||||||
: YGDirectionLTR;
|
: YGDirectionLTR;
|
||||||
} else {
|
} else {
|
||||||
return style_.direction;
|
return style_.direction;
|
||||||
@@ -550,10 +550,10 @@ void YGNode::cloneChildrenIfNeeded() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const YGNodeRef firstChild = children_.front();
|
const YGNodeRef firstChild = children_.front();
|
||||||
if (firstChild->getParent() == this) {
|
if (firstChild->getOwner() == this) {
|
||||||
// If the first child has this node as its parent, we assume that it is
|
// If the first child has this node as its owner, we assume that it is
|
||||||
// already unique. We can do this because if we have it has a child, that
|
// already unique. We can do this because if we have it has a child, that
|
||||||
// means that its parent was at some point cloned which made that subtree
|
// means that its owner was at some point cloned which made that subtree
|
||||||
// immutable. We also assume that all its sibling are cloned as well.
|
// immutable. We also assume that all its sibling are cloned as well.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -569,7 +569,7 @@ void YGNode::cloneChildrenIfNeeded() {
|
|||||||
newChild = YGNodeClone(oldChild);
|
newChild = YGNodeClone(oldChild);
|
||||||
}
|
}
|
||||||
replaceChild(newChild, i);
|
replaceChild(newChild, i);
|
||||||
newChild->setParent(this);
|
newChild->setOwner(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,8 +577,8 @@ void YGNode::markDirtyAndPropogate() {
|
|||||||
if (!isDirty_) {
|
if (!isDirty_) {
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
setLayoutComputedFlexBasis(YGUndefined);
|
setLayoutComputedFlexBasis(YGUndefined);
|
||||||
if (parent_) {
|
if (owner_) {
|
||||||
parent_->markDirtyAndPropogate();
|
owner_->markDirtyAndPropogate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -592,7 +592,7 @@ void YGNode::markDirtyAndPropogateDownwards() {
|
|||||||
|
|
||||||
float YGNode::resolveFlexGrow() {
|
float YGNode::resolveFlexGrow() {
|
||||||
// Root nodes flexGrow should always be 0
|
// Root nodes flexGrow should always be 0
|
||||||
if (parent_ == nullptr) {
|
if (owner_ == nullptr) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
if (!style_.flexGrow.isUndefined()) {
|
if (!style_.flexGrow.isUndefined()) {
|
||||||
@@ -605,7 +605,7 @@ float YGNode::resolveFlexGrow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float YGNode::resolveFlexShrink() {
|
float YGNode::resolveFlexShrink() {
|
||||||
if (parent_ == nullptr) {
|
if (owner_ == nullptr) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
if (!style_.flexShrink.isUndefined()) {
|
if (!style_.flexShrink.isUndefined()) {
|
||||||
|
@@ -23,7 +23,7 @@ struct YGNode {
|
|||||||
YGStyle style_;
|
YGStyle style_;
|
||||||
YGLayout layout_;
|
YGLayout layout_;
|
||||||
uint32_t lineIndex_;
|
uint32_t lineIndex_;
|
||||||
YGNodeRef parent_;
|
YGNodeRef owner_;
|
||||||
YGVector children_;
|
YGVector children_;
|
||||||
YGNodeRef nextChild_;
|
YGNodeRef nextChild_;
|
||||||
YGConfigRef config_;
|
YGConfigRef config_;
|
||||||
@@ -49,7 +49,7 @@ struct YGNode {
|
|||||||
YGStyle style,
|
YGStyle style,
|
||||||
const YGLayout& layout,
|
const YGLayout& layout,
|
||||||
uint32_t lineIndex,
|
uint32_t lineIndex,
|
||||||
YGNodeRef parent,
|
YGNodeRef owner,
|
||||||
const YGVector& children,
|
const YGVector& children,
|
||||||
YGNodeRef nextChild,
|
YGNodeRef nextChild,
|
||||||
YGConfigRef config,
|
YGConfigRef config,
|
||||||
@@ -69,7 +69,12 @@ struct YGNode {
|
|||||||
// For Performance reasons passing as reference.
|
// For Performance reasons passing as reference.
|
||||||
YGLayout& getLayout();
|
YGLayout& getLayout();
|
||||||
uint32_t getLineIndex() const;
|
uint32_t getLineIndex() const;
|
||||||
YGNodeRef getParent() const;
|
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
|
||||||
|
// the YogaTree that a YGNode belongs to.
|
||||||
|
// This method will return the parent of the YGNode when a YGNode only belongs
|
||||||
|
// to one YogaTree or nullptr when the YGNode is shared between two or more
|
||||||
|
// YogaTrees.
|
||||||
|
YGNodeRef getOwner() const;
|
||||||
YGVector getChildren() const;
|
YGVector getChildren() const;
|
||||||
uint32_t getChildrenCount() const;
|
uint32_t getChildrenCount() const;
|
||||||
YGNodeRef getChild(uint32_t index) const;
|
YGNodeRef getChild(uint32_t index) const;
|
||||||
@@ -111,12 +116,12 @@ struct YGNode {
|
|||||||
void setStyleAlignContent(YGAlign alignContent);
|
void setStyleAlignContent(YGAlign alignContent);
|
||||||
void setLayout(const YGLayout& layout);
|
void setLayout(const YGLayout& layout);
|
||||||
void setLineIndex(uint32_t lineIndex);
|
void setLineIndex(uint32_t lineIndex);
|
||||||
void setParent(YGNodeRef parent);
|
void setOwner(YGNodeRef owner);
|
||||||
void setChildren(const YGVector& children);
|
void setChildren(const YGVector& children);
|
||||||
void setNextChild(YGNodeRef nextChild);
|
void setNextChild(YGNodeRef nextChild);
|
||||||
void setConfig(YGConfigRef config);
|
void setConfig(YGConfigRef config);
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastParentDirection(YGDirection direction);
|
void setLayoutLastOwnerDirection(YGDirection direction);
|
||||||
void setLayoutComputedFlexBasis(float computedFlexBasis);
|
void setLayoutComputedFlexBasis(float computedFlexBasis);
|
||||||
void setLayoutComputedFlexBasisGeneration(
|
void setLayoutComputedFlexBasisGeneration(
|
||||||
uint32_t computedFlexBasisGeneration);
|
uint32_t computedFlexBasisGeneration);
|
||||||
@@ -132,7 +137,7 @@ struct YGNode {
|
|||||||
const YGDirection direction,
|
const YGDirection direction,
|
||||||
const float mainSize,
|
const float mainSize,
|
||||||
const float crossSize,
|
const float crossSize,
|
||||||
const float parentWidth);
|
const float ownerWidth);
|
||||||
void setAndPropogateUseLegacyFlag(bool useLegacyFlag);
|
void setAndPropogateUseLegacyFlag(bool useLegacyFlag);
|
||||||
void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
|
void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
|
||||||
void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
|
void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
|
||||||
@@ -143,7 +148,7 @@ struct YGNode {
|
|||||||
YGValue marginTrailingValue(const YGFlexDirection axis) const;
|
YGValue marginTrailingValue(const YGFlexDirection axis) const;
|
||||||
YGValue resolveFlexBasisPtr() const;
|
YGValue resolveFlexBasisPtr() const;
|
||||||
void resolveDimension();
|
void resolveDimension();
|
||||||
YGDirection resolveDirection(const YGDirection parentDirection);
|
YGDirection resolveDirection(const YGDirection ownerDirection);
|
||||||
void clearChildren();
|
void clearChildren();
|
||||||
/// Replaces the occurrences of oldChild with newChild
|
/// Replaces the occurrences of oldChild with newChild
|
||||||
void replaceChild(YGNodeRef oldChild, YGNodeRef newChild);
|
void replaceChild(YGNodeRef oldChild, YGNodeRef newChild);
|
||||||
|
458
yoga/Yoga.cpp
458
yoga/Yoga.cpp
File diff suppressed because it is too large
Load Diff
@@ -81,14 +81,14 @@ WIN_EXPORT void YGNodeInsertChild(const YGNodeRef node,
|
|||||||
WIN_EXPORT void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef child);
|
WIN_EXPORT void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef child);
|
||||||
WIN_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef node);
|
WIN_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef node);
|
||||||
WIN_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index);
|
WIN_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index);
|
||||||
WIN_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node);
|
WIN_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node);
|
||||||
WIN_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node);
|
WIN_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node);
|
||||||
WIN_EXPORT void YGNodeSetChildren(YGNodeRef const parent, const YGNodeRef children[], const uint32_t count);
|
WIN_EXPORT void YGNodeSetChildren(YGNodeRef const parent, const YGNodeRef children[], const uint32_t count);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
|
WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
|
||||||
const float availableWidth,
|
const float availableWidth,
|
||||||
const float availableHeight,
|
const float availableHeight,
|
||||||
const YGDirection parentDirection);
|
const YGDirection ownerDirection);
|
||||||
|
|
||||||
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
||||||
// set.
|
// set.
|
||||||
|
Reference in New Issue
Block a user