Hi!
I've just been looking - again! - at using Juce for new iOS & Android apps.
Clearly, these need to scale well on different screens.
So, fixed positioning and fixed sizing simply doesn't cut the mustard.
However, Juce doesn't seem to have a layout system.
That said, of course a simple solution would be to have a screen configured such that it could simply, where required, automatically reposition and re-size all elements from their original values, to scale to the current screen size.
As a quick experiment, I've done this in my "resizable master component" .h file:
bool mbSetSizesYet;
Rectangle<float> mOriginalSize;
std::vector< float> mComponentOriginalPositionX;
std::vector< float> mComponentOriginalPositionY;
std::vector< float> mComponentOriginalWidth;
std::vector< float> mComponentOriginalHeight;
And this in the .cpp file...:
void ResizingGuiComponent::resized()
{
textButton->setBounds (32, 32, 150, 24);
groupComponent->setBounds (48, 144, 200, 150);
comboBox->setBounds (288, 72, 150, 24);
treeView->setBounds (376, 208, 150, 150);
textEditor->setBounds (40, 88, 150, 24);
//[UserResized] Add your own custom resize handling here..
// Note the code above, is the fixing size/position code always put there by the Introjucer!
if (mbSetSizesYet == false)
{
// Capture the initial component size and position information...
mbSetSizesYet = true;
// TODO - do this with NamedValueSet ...?
mOriginalSize = Rectangle<float>(getWidth(), getHeight());
int lChildComponentCount = this->getNumChildComponents();
int i;
for (i = 0; i < lChildComponentCount; i++) {
Component *lpChildComponent = getChildComponent(i);
float lfX = lpChildComponent->getX();
float lfY = lpChildComponent->getY();
float lfWidth = lpChildComponent->getWidth();
float lfHeight = lpChildComponent->getHeight();
printf("%d, x=%g,y=%g,w=%g,h=%g\n", i, lfX, lfY, lfWidth, lfHeight);
mComponentOriginalPositionX.push_back(lfX);
mComponentOriginalPositionY.push_back(lfY);
mComponentOriginalWidth.push_back(lfWidth);
mComponentOriginalHeight.push_back(lfHeight);
lfX = mComponentOriginalPositionX[i];
lfY = mComponentOriginalPositionY[i];
lfWidth = mComponentOriginalWidth[i];
lfHeight = mComponentOriginalHeight[i];
printf("CHECK: %d, x=%g,y=%g,w=%g,h=%g\n", i, lfX, lfY, lfWidth, lfHeight);
}
}
else
{
// Re-size and re-position!
float lfXScale = ((float)getWidth()) / mOriginalSize.getWidth();
float lfYScale = ((float)getHeight()) / mOriginalSize.getHeight();
int lChildComponentCount = this->getNumChildComponents();
int i;
for (i = 0; i < lChildComponentCount; i++) {
Component *lpChildComponent = getChildComponent(i);
float lfX = mComponentOriginalPositionX[i] * lfXScale;
float lfY = mComponentOriginalPositionY[i] * lfYScale;
float lfWidth = mComponentOriginalWidth[i] * lfXScale;
float lfHeight = mComponentOriginalHeight[i] * lfYScale;
printf("RESIZE: %d, x=%g,y=%g,w=%g,h=%g\n", i, lfX, lfY, lfWidth, lfHeight);
lpChildComponent->setBounds(lfX, lfY, lfWidth, lfHeight);
}
}
//[/UserResized]
}
Anyhow! The question is: has anybody out there in Juce land got a better solution than this?
Jules - have you got any bright ideas?! :)
Pete