Flexbox and Group Component falling down

This drive me nuts and I dont see any error. The code is so simple but it not working.
When I try to resize the gropupcomponent which is part of flexbox its going down by his hight


see here

CODE:

#include "MainComponent.h"

MainComponent::MainComponent()
{
  
    groupMainA.setName("groupMainA");
    groupMainA.setText("groupMainA");
    groupMainA.setTextLabelPosition(juce::Justification::centredLeft);
    addAndMakeVisible(groupMainA);

    setSize (800, 900);
}
MainComponent::~MainComponent()
{
}

void MainComponent::paint (juce::Graphics& g)
{}

void MainComponent::resized()
{

    fl.flexDirection = juce::FlexBox::Direction::column;
    fl.flexWrap = juce::FlexBox::Wrap::wrap;
    fl.alignContent = juce::FlexBox::AlignContent::flexStart;
    fl.alignItems = juce::FlexBox::AlignItems::flexStart;
 
    juce::FlexItem addGroupMainA(100, 100, groupMainA);
    fl.items.addArray({ addGroupMainA });
    fl.performLayout(getLocalBounds().toFloat());
}
#include <JuceHeader.h>

class MainComponent  : public juce::Component
{
public:

    MainComponent();
    ~MainComponent() override;

    juce::FlexBox fl;
    juce::GroupComponent groupMainA;

    void paint (juce::Graphics&) override;
    void resized() override;


private:
        JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};

What Im doing wrong?

You should declare the Flexbox locally in the resized method instead of having it as a class member.

1 Like

OMG. You have absolutely right this fix the problem.
Now I’m curious why?

If you add into the existing items in the Flexbox, the old ones are not cleared. (And will appear as empty space in the layout)

1 Like