Skip to content

Child with MinWidth, Flex and Wrap lays outside of parent boundary #323

Description

@Jaydee2190

Thanks for an amazing library, I have run into a small issue when using flex wrap and having a single item in a row that has its flex attribute set. Just before the item wraps there's a point where it's layout is outside the layout container bounds. I've narrowed it down to layout.computedFlexBasis being 0, and the following line doesn't break...but don't know the inner workings well enough...

if (sizeConsumedOnCurrentLine + outerFlexBasis > availableInnerMainDim && isNodeFlexWrap &&
        itemsOnLine > 0) {
      break;
    }

The assertion will happen when i (the width) is 119... In which case the item being laid out will have a left of 119 and a width of 20, putting it out of bounds... (It does get worse when the width is 110, the Right will be at 130. This is because i've set a minimum width).

I hope my test code is enough to demonstrate the problem, and if i'm making some wrong assumption, please correct me! (If there is no minimum width there isn't an issue, its the minimum width that's pushing it outside the bounds.)

        YGNodeRef container=YGNodeNew();
        YGNodeStyleSetFlexDirection(container,YGFlexDirectionRow);
        YGNodeStyleSetFlexWrap(container, YGWrapWrap);
        
        YGNodeRef itemA=YGNodeNew();
        YGNodeStyleSetWidth(itemA, 100.f);
        YGNodeStyleSetHeight(itemA,25.f);
        YGNodeInsertChild(container, itemA, 0);
        
        YGNodeRef itemB=YGNodeNew();
        YGNodeStyleSetWidth(itemB, 100.f);
        YGNodeStyleSetHeight(itemB,25.f);
        YGNodeStyleSetMinWidth(itemB, 20.f);
        YGNodeStyleSetFlex(itemB, 1.f);
        
        YGNodeInsertChild(container, itemB, 1);
        
        for (int i=200;--i>=50;)
        {
            YGNodeCalculateLayout(container, i, 200.f, YGDirectionLTR);
            printf("Width:%d - (Flex Item B Left:%f Top:%f Width:%f Height:%f)\n",i,YGNodeLayoutGetLeft(itemB),YGNodeLayoutGetTop(itemB),YGNodeLayoutGetWidth(itemB),YGNodeLayoutGetHeight(itemB));
            // will assert from 119-100
            assert(YGNodeLayoutGetLeft(itemB)+YGNodeLayoutGetWidth(itemB) <=i);
            // assert(YGNodeLayoutGetRight(itemB) <=i); // doesn't work GetRight == 0
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions