facebook / yoga

Yoga is an embeddable layout engine targeting web standards.
https://yogalayout.dev/
MIT License
17.25k stars 1.42k forks source link

[c++]set the fex property 1 to the node with measueFunc , the node width will be 0 #1682

Closed yutoabc closed 2 months ago

yutoabc commented 2 months ago

Report

[c++]set the fex property 1 to the node with measueFunc , the node width will be 0

Issues and Steps to Reproduce

the code sample: YGSize testFunc(YGNodeConstRef node, float availableWidth, YGMeasureMode widthMode, float availableHeight, YGMeasureMode heightMode) { printf("test fun w=%f,wm=%d,h=%f,hm=%d\n,", availableWidth, widthMode, availableHeight, heightMode); return {100.f, 100.f}; } void main(){ YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignCenter); YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); YGNodeStyleSetWidth(root, 300.f); YGNodeStyleSetWidth(root, 300.f);

YGNodeRef parent1 = YGNodeNew(); YGNodeStyleSetAlignItems(parent1, YGAlignCenter); YGNodeStyleSetFlexDirection(parent1, YGFlexDirectionRow);

YGNodeRef child1 = YGNodeNew(); YGNodeSetContext(child1, "child1"); YGNodeSetMeasureFunc(child1, testFunc); YGNodeStyleSetFlex(child1, 1);

YGNodeRef child2 = YGNodeNew(); YGNodeSetContext(child2, "child2"); YGNodeSetMeasureFunc(child2, testFunc); YGNodeStyleSetFlex(child2, 1);

YGNodeInsertChild(root, parent1, 0); YGNodeInsertChild(parent1, child1, 0); YGNodeInsertChild(parent1, child2, 1);

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); printf( "root (%f,%f),parent(%f,%f), child1(%f,%f)child2(%f,%f)\n", YGNodeLayoutGetWidth(root), YGNodeLayoutGetHeight(root), YGNodeLayoutGetWidth(parent1), YGNodeLayoutGetHeight(parent1), YGNodeLayoutGetWidth(child1), YGNodeLayoutGetHeight(child1), YGNodeLayoutGetWidth(child2), YGNodeLayoutGetHeight(child2)); }

Expected Behavior

the child node should have 100 width return in MeasureFunc

Actual Behavior

the child node width is 0, log output below , test fun w=0.000000,wm=1,h=nan,hm=0 ,test fun w=0.000000,wm=1,h=nan,hm=0 ,root (300.000000,100.000000),parent(0.000000,100.000000), child1(0.000000,100.000000)child2(0.000000,100.000000)

yutoabc commented 2 months ago

i think it's because the flex basis is 0 default