I’m running into a strange problem when constructing nested FlexBoxes (a vertical FlexBox containing horizontal FlexBoxes). The code compiles fine and looks like it should work; performLayout calls performLayout on the child FlexBoxes. But for some reason at that point the child FlexBoxes no longer have any items, even though I very clearly added them in the loop. It seems the child hboxes items array is no longer initialized at all. Is this related to the hbox going out of scope? How can I get my desired behavior?
auto rowHeight = bounds.getHeight() / numRows;
for (const auto& row : rows)
{
auto area = bounds.removeFromTop(rowHeight);
FlexBox hbox{ FlexBox::Direction::row, FlexBox::Wrap::wrap, FlexBox::AlignContent::center, FlexBox::AlignItems::center, FlexBox::JustifyContent::center };
for (const auto& control : *row)
{
auto& comp = controls[control.id];
hbox.items.add(FlexItem(*comp).withMinWidth(30));
}
vbox.items.add(FlexItem(hbox).withMinHeight(50));
}
vbox.performLayout(bounds);
FlexItem::FlexItem ( FlexBox & flexBoxToControl ) noexcept
Creates an item that represents an embedded FlexBox.
This class will not create a copy of the supplied flex box. You need to ensure that the life-time of flexBoxToControl is longer than the FlexItem.
But hbox goes out of scope, because it is declared in the loop body.