Feature hidden nodes #302

Closed
roxlu wants to merge 8 commits from feature-hidden-nodes into master
2 changed files with 44 additions and 0 deletions

View File

@@ -98,6 +98,7 @@ typedef struct YGNode {
YGNodeRef parent; YGNodeRef parent;
YGNodeListRef children; YGNodeListRef children;
bool isDirty; bool isDirty;
bool isVisible;
struct YGNode *nextChild; struct YGNode *nextChild;
@@ -190,6 +191,7 @@ static void YGNodeInit(const YGNodeRef node) {
node->children = NULL; node->children = NULL;
node->hasNewLayout = true; node->hasNewLayout = true;
node->isDirty = false; node->isDirty = false;
node->isVisible = true;
node->style.flex = YGUndefined; node->style.flex = YGUndefined;
node->style.flexGrow = YGUndefined; node->style.flexGrow = YGUndefined;
@@ -348,6 +350,22 @@ bool YGNodeIsDirty(const YGNodeRef node) {
return node->isDirty; return node->isDirty;
} }
void YGNodeHide(const YGNodeRef node) {
node->isVisible = false;
node->isDirty = false; /* See https://github.com/facebook/css-layout/issues/241 */
YGNodeMarkDirty(node);
}
void YGNodeShow(const YGNodeRef node) {
node->isVisible = true;
node->isDirty = false; /* See https://github.com/facebook/css-layout/issues/241 */
YGNodeMarkDirty(node);
}
bool YGNodeIsVisible(const YGNodeRef node) {
return node->isVisible;
}
void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) { void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
if (memcmp(&dstNode->style, &srcNode->style, sizeof(YGStyle)) != 0) { if (memcmp(&dstNode->style, &srcNode->style, sizeof(YGStyle)) != 0) {
memcpy(&dstNode->style, &srcNode->style, sizeof(YGStyle)); memcpy(&dstNode->style, &srcNode->style, sizeof(YGStyle));
@@ -1531,6 +1549,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
// STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
for (uint32_t i = 0; i < childCount; i++) { for (uint32_t i = 0; i < childCount; i++) {
const YGNodeRef child = YGNodeListGet(node->children, i); const YGNodeRef child = YGNodeListGet(node->children, i);
if (NULL != child && false == YGNodeIsVisible(child)) {
continue;
}
if (performLayout) { if (performLayout) {
// Set the initial position (relative to the parent). // Set the initial position (relative to the parent).
@@ -1605,6 +1626,10 @@ static void YGNodelayoutImpl(const YGNodeRef node,
// Add items to the current line until it's full or we run out of items. // Add items to the current line until it's full or we run out of items.
for (uint32_t i = startOfLineIndex; i < childCount; i++, endOfLineIndex++) { for (uint32_t i = startOfLineIndex; i < childCount; i++, endOfLineIndex++) {
const YGNodeRef child = YGNodeListGet(node->children, i); const YGNodeRef child = YGNodeListGet(node->children, i);
if (NULL != child && false == YGNodeIsVisible(child)) {
continue;
}
child->lineIndex = lineCount; child->lineIndex = lineCount;
if (child->style.positionType != YGPositionTypeAbsolute) { if (child->style.positionType != YGPositionTypeAbsolute) {
@@ -1939,6 +1964,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) {
const YGNodeRef child = YGNodeListGet(node->children, i); const YGNodeRef child = YGNodeListGet(node->children, i);
if (NULL != child && false == YGNodeIsVisible(child)) {
continue;
}
if (child->style.positionType == YGPositionTypeAbsolute && if (child->style.positionType == YGPositionTypeAbsolute &&
YGNodeIsLeadingPosDefined(child, mainAxis)) { YGNodeIsLeadingPosDefined(child, mainAxis)) {
@@ -2011,6 +2039,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
if (performLayout) { if (performLayout) {
for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) {
const YGNodeRef child = YGNodeListGet(node->children, i); const YGNodeRef child = YGNodeListGet(node->children, i);
if (NULL != child && false == YGNodeIsVisible(child)) {
continue;
}
if (child->style.positionType == YGPositionTypeAbsolute) { if (child->style.positionType == YGPositionTypeAbsolute) {
// If the child is absolutely positioned and has a // If the child is absolutely positioned and has a
@@ -2136,6 +2167,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
float lineHeight = 0; float lineHeight = 0;
for (ii = startIndex; ii < childCount; ii++) { for (ii = startIndex; ii < childCount; ii++) {
const YGNodeRef child = YGNodeListGet(node->children, ii); const YGNodeRef child = YGNodeListGet(node->children, ii);
if (NULL != child && false == YGNodeIsVisible(child)) {
continue;
}
if (child->style.positionType == YGPositionTypeRelative) { if (child->style.positionType == YGPositionTypeRelative) {
if (child->lineIndex != i) { if (child->lineIndex != i) {
@@ -2155,6 +2189,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
if (performLayout) { if (performLayout) {
for (ii = startIndex; ii < endIndex; ii++) { for (ii = startIndex; ii < endIndex; ii++) {
const YGNodeRef child = YGNodeListGet(node->children, ii); const YGNodeRef child = YGNodeListGet(node->children, ii);
if (NULL != child && false == YGNodeIsVisible(child)) {
continue;
}
if (child->style.positionType == YGPositionTypeRelative) { if (child->style.positionType == YGPositionTypeRelative) {
switch (YGNodeAlignItem(node, child)) { switch (YGNodeAlignItem(node, child)) {
@@ -2246,6 +2283,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
if (needsMainTrailingPos || needsCrossTrailingPos) { if (needsMainTrailingPos || needsCrossTrailingPos) {
for (uint32_t i = 0; i < childCount; i++) { for (uint32_t i = 0; i < childCount; i++) {
const YGNodeRef child = YGNodeListGet(node->children, i); const YGNodeRef child = YGNodeListGet(node->children, i);
if (NULL != child && false == YGNodeIsVisible(child)) {
continue;
}
if (needsMainTrailingPos) { if (needsMainTrailingPos) {
YGNodeSetChildTrailingPosition(node, child, mainAxis); YGNodeSetChildTrailingPosition(node, child, mainAxis);

View File

@@ -80,6 +80,10 @@ WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node); WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node);
WIN_EXPORT bool YGNodeIsDirty(const YGNodeRef node); WIN_EXPORT bool YGNodeIsDirty(const YGNodeRef node);
WIN_EXPORT void YGNodeHide(const YGNodeRef node);
WIN_EXPORT void YGNodeShow(const YGNodeRef node);
WIN_EXPORT bool YGNodeIsVisible(const YGNodeRef node);
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options); WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
WIN_EXPORT bool YGValueIsUndefined(const float value); WIN_EXPORT bool YGValueIsUndefined(const float value);