I’m migrating some code from JUCE 6 to 7 and have hit a change in behaviour.
I’m using Grid::performLayout
to centre a component of even-numbered dimensions inside a component with odd-numbered dimensions.
Until this JUCE 7.0.3 commit, though the centred bounds (left, right, top & bottom) fall between integers they all would have been rounded in the same direction, preserving the size of the child component - but with this commit the dimensions of the child component (if previously an integer) will be enlarged.
According to the commit message, this has been done to preserve the behaviour of very small controls, but it has unfortunate side effects for us.
Would it be possible to opt-out of this behaviour? Preserving the sizes of components by default would seem to be a desirable property where possible even when their centred position needs to be rounded to the nearest pixel.
Here’s some code to illustrate the problem:
juce::Component myChild;
myChild.setBounds (100, 100, 100, 100);
juce::GridItem item {myChild};
item.alignSelf = juce::GridItem::AlignSelf::center;
item.justifySelf = juce::GridItem::JustifySelf::center;
item.width = myChild.getWidth();
item.height = myChild.getHeight();
juce::Grid grid;
grid.templateColumns = {juce::Grid::Fr{1}};
grid.templateRows = {juce::Grid::Fr{1}};
grid.items = {item};
grid.performLayout ({0, 0, 200, 200});
// these will succeed...
jassert(myChild.getWidth() == 100);
jassert(myChild.getHeight() == 100);
grid.performLayout ({0, 0, 199, 199});
// ... but these will fail
jassert(myChild.getWidth() == 100);
jassert(myChild.getHeight() == 100);
Any advice you can offer would be appreciated!
Steve.