FlexBox Confusion

I have a very basic usage of FlexBox that isn’t showing anything.
In my contructor:

fileLabel.setText("File not selected", juce::dontSendNotification);
fileLabel.setFont(15);
topControls.items.add(juce::FlexItem(fileLabel));
addAndMakeVisible(fileLabel);

In my resize:

auto bounds = getLocalBounds();

auto top = bounds.removeFromTop(15);
topControls.performLayout(top);

When I debug it seems items is empty in the resize method which doesn’t make any sense to me. Also when I add the item in the resize method it doesn’t work either. Is there something very basic I’m missing here?

Can’t explain why items would be empty, but the reason it’s not visible even when you add the items in resized() is probably because you haven’t specified any minimum size, so it’s just getting set to a size of 0x0.

Either set the minWidth and minHeight of the item, or do something like setting the item’s flexGrow to 1 and the FlexBox’s alignItems to stretch.

2 Likes

FlexBox seems to just not work unless it’s all initialized within the resize method, although I do not understand why. This is also how the JUCE tutorial uses it.