Button disappears on resize


#1

Hi All,
I’m new to JUCE and I’m trying to work with a FlexBox.
I created a new GUI project and added a text button to the main component and I’m trying to use a FlexBox for the layout (obviously, I’ll add more controls later, it’s not just for the button :slight_smile: ).
It appears to work fine when the app starts but when I try to resize the window the button just disappears!
What am I missing?

Here is my code:

MainComponent::MainComponent() 
{
    setSize (600, 400);

    _saveButton.setButtonText("Save");
    _saveButton.changeWidthToFitText(30);
    addAndMakeVisible(_saveButton);
    _saveButton.onClick = std::bind(&MainComponent::onSaveButtonClick, this);
}

void MainComponent::onSaveButtonClick()
{

}

void MainComponent::paint (Graphics& g)
{
    // (Our component is opaque, so we must completely fill the background with a solid colour)
    g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));

}

void MainComponent::resized()
{
    // This is called when the MainComponent is resized.
    // If you add any child components, this is where you should
    // update their positions.
    auto r = getLocalBounds();

    FlexBox sidebar;
    sidebar.items.add( _saveButton );

    sidebar.performLayout(r);
}

#2

You need to specify the FlexBox parameters.

see this constructor
https://docs.juce.com/master/classFlexBox.html#a4c44bc8d44580b62d02e42ee4b53b9d5