diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 50cfd98f..9f2c2666 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -328,6 +328,12 @@ void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) { resolveRef(node)->setPrintFunc(printFunc); } +void YGNodeSetAlwaysFormsContainingBlock( + YGNodeRef node, + bool alwaysFormsContainingBlock) { + resolveRef(node)->setAlwaysFormsContainingBlock(alwaysFormsContainingBlock); +} + #ifdef DEBUG void YGNodePrint(const YGNodeConstRef node, const YGPrintOptions options) { yoga::print(resolveRef(node), scopedEnum(options)); diff --git a/yoga/YGNode.h b/yoga/YGNode.h index b267cde1..58c966fd 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -270,6 +270,17 @@ typedef void (*YGPrintFunc)(YGNodeConstRef node); */ YG_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc); +/** + * Make it so that this node will always form a containing block for any + * descendant nodes. This is useful for when a node has a property outside of + * of Yoga that will form a containing block. For example, transforms or some of + * the others listed in + * https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block + */ +YG_EXPORT void YGNodeSetAlwaysFormsContainingBlock( + YGNodeRef node, + bool alwaysFormsContainingBlock); + /** * Print a node to log output. */ diff --git a/yoga/algorithm/AbsoluteLayout.cpp b/yoga/algorithm/AbsoluteLayout.cpp index 886aae13..230dfb5d 100644 --- a/yoga/algorithm/AbsoluteLayout.cpp +++ b/yoga/algorithm/AbsoluteLayout.cpp @@ -528,7 +528,9 @@ void layoutAbsoluteDescendants( if (needsTrailingPosition(crossAxis)) { setChildTrailingPosition(currentNode, child, crossAxis); } - } else if (child->getStyle().positionType() == PositionType::Static) { + } else if ( + child->getStyle().positionType() == PositionType::Static && + !child->alwaysFormsContainingBlock()) { const Direction childDirection = child->resolveDirection(currentNodeDirection); const float childMainOffsetFromContainingBlock = diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index 17703605..6cf29621 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -2034,7 +2034,7 @@ static void calculateLayoutImpl( // Let the containing block layout its absolute descendants. By definition // the containing block will not be static unless we are at the root. if (node->getStyle().positionType() != PositionType::Static || - depth == 1) { + node->alwaysFormsContainingBlock() || depth == 1) { layoutAbsoluteDescendants( node, node, diff --git a/yoga/node/Node.h b/yoga/node/Node.h index 712f154e..b1971a69 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -48,6 +48,10 @@ class YG_EXPORT Node : public ::YGNode { return context_; } + bool alwaysFormsContainingBlock() const { + return alwaysFormsContainingBlock_; + } + void print(); bool getHasNewLayout() const { @@ -242,6 +246,10 @@ class YG_EXPORT Node : public ::YGNode { context_ = context; } + void setAlwaysFormsContainingBlock(bool alwaysFormsContainingBlock) { + alwaysFormsContainingBlock_ = alwaysFormsContainingBlock; + } + void setPrintFunc(YGPrintFunc printFunc) { printFunc_ = printFunc; } @@ -369,6 +377,7 @@ class YG_EXPORT Node : public ::YGNode { bool hasNewLayout_ : 1 = true; bool isReferenceBaseline_ : 1 = false; bool isDirty_ : 1 = false; + bool alwaysFormsContainingBlock_ : 1 = false; NodeType nodeType_ : bitCount() = NodeType::Default; void* context_ = nullptr; YGMeasureFunc measureFunc_ = {nullptr};