I’ve found a strange behaviour, and I don’t understand how to solve it.
Typically, I’ve a main component (square : 256x256) containing few other components (circles that fit perfectly inside the square, radius:128)
I want to add a label to the top left of the main component, enlarging the bounds.
I’ve tried (pseudo) code like this:
mainBB = mainComponent->getBounds(); label = new label; // position label so that it's bottom right corner is on the top left corner of mainComponent labelBB = label->getBounds(); finalBB = mainBB.getUnion(labelBB.translated(- mainBB.topLeftCorner); newTopLeftCornerDiff = mainBB.topLeftCorner - labelBB.topLeftCorner; labelBB.setTopLeftCorner(0,0); // Now make it relative to parent addAndMakeVisible(labelBB); mainComponent->setBounds(finalBB);
This works, but previous child component are now shifted to the top left of newTopLeftCornerDiff.
So, I’ve added :
addAndMakeVisible(labelBB); // Shift previous child component for all child, child->setTopLeftPosition(child->topLeftPosition + newTopLeftCornerAbsDiff) mainComponent->setBounds(finalBB);
But because the 2 setBounds calls are not transacted, I see the child component going down (just after setTopLeftPosition) and before mainComponent->setBounds, and then fitting correctly.
I’ve also tried to hide it before moving it (to avoid drawing it on the bad position), and making it visible afterward, but it seems the parent doesn’t care about this, and still the child component pop down and then back to the right position.
So, is there a way to set the bounds of a component without actually repainting it (I’ve debugged the code, and the child component doesn’t even repaint while being moved), or to enlarge a parent component without moving its children absolute position ?
Thanks, this popping artifact is terribly distracting.