Idea for debugging flexbox and flexitem

gui

#1

Attempting to debug what I initially thought was a simple use of flexbox and flexitem. But window shows up empty after an evening of trying different things.

Which got me thinking – would be nice if there was some sort of recursive method to call in FlexBox which would generate strings or a string explaining what it is resizing, and the reason why it is doing it.

So the same way we call flexbox.performLayout® in resized(), maybe we could also have one that passes in a String, or…?


#2

@daniel came up with this little gem when I was learning how to use FlexBox:

void FlexBox::performLayout (Rectangle<float> targetArea)
//snip...
for (auto& item : items)
        {
            item.currentBounds += targetArea.getPosition();

            if (auto comp = item.associatedComponent)
            {
                //comp->setBounds (item.currentBounds.getSmallestIntegerContainer());
                //https://github.com/WeAreROLI/JUCE/commit/d6ea60b2e5ff8dc0e15645b5911b7e81886b06fe
                auto position = item.currentBounds.getPosition().roundToInt();
                comp->setBounds(position.getX(),
                                position.getY(),
                                roundToInt(item.currentBounds.getRight()) - position.getX(),
                                roundToInt(item.currentBounds.getBottom()) - position.getY() );

                DBG ("placed: " + comp->getName() + ": " + item.currentBounds.getSmallestIntegerContainer().toString());
            }

            if (auto box = item.associatedFlexBox)
                box->performLayout (item.currentBounds);
        }

#3

wow, I don’t remember at all, so maybe I don’t deserve that credits… but thanks, if I do :wink:


#4

lol you just added the DBG statement, but it was clutch placement!