Grid/Flexbox? Layout grid of squares with dynamic but equal row sizes

Hi there- I have a parent component containing 16 child components that should always be represented as squares on a grid of equal row sizes.

Depending on the aspect ratio of the parent component, the child components should be laid out into a grid format of 1x16, 2x8 or 4x4.
The sum of all the row’s heights should always be equal to the parent’s height.
The child components can resize, but should always remain square in doing so.
If meeting these requirements will not fully fill the parent, the grid of child components should remain centered, with equal sized gaps to the left & right.

What is the simplest way to approach this in Juce? I’m unsure if I should be looking to Grid’s autoflow, a means of getting FlexBox to wrap only with equal row sizes, nesting these approaches or something else.