First, my apologies for what is probably going to be a dumb question but I'm utterly stumped :/
As I understand the documentation, I should be able to add code to the parent component's resized() callback to resize and reposition its child components. However, the app crashes when I attempt this, even with the basic app assembled by IntroJucer.
As an example, below are the relevant bits from the IntroJucer constructed app. The only I change I made to that boilerplate was to add a label component to the MainComponnent.h file. The setBounds() call in the resized() function is a bit silly because it just repeats the exact same call as occurs in the main component's constructor. Ideally, I'd make a call to reposition the label according to its parent's new size but even this simple call fails. If I comment out the line in resized(), the app works fine. So, what am I missing?!?!?
Thank you in advance for any response! BTW I'm using VS2010 on Windows 7 64bit if that matters.
/*
Main.cpp
<snip> ... just the constructor bit
*/
MainWindow() : DocumentWindow ("MainWindow",
Colours::lightgrey,
DocumentWindow::allButtons)
{
setContentOwned (new MainContentComponent(), true);
centreWithSize (getWidth(), getHeight());
setVisible (true);
}
/*
MainComponent.cpp
<snip> ... just the constructor and resized() bits
*/
MainContentComponent::MainContentComponent()
{
setSize (500, 400);
label = new Label ("label", "eat at joe's");
label->setBounds(100, 100, 120, 20);
addAndMakeVisible (label);
}
void MainContentComponent::resized()
{
label->setBounds(100, 100, 120, 20);
}