@Override
public Size requiredSize(final Size availableSpace) {
int lineHeight = 0;
int lineWidth = ViewConstants.HPADDING;
final Size requiredSize = new Size();
for (final View button : getSubviews()) {
final Size buttonSize = button.getRequiredSize(availableSpace);
lineWidth += buttonSize.getWidth() + ViewConstants.HPADDING;
if (lineWidth >= availableSpace.getWidth()) {
lineWidth = ViewConstants.HPADDING;
requiredSize.extendHeight(lineHeight + ViewConstants.VPADDING);
lineHeight = 0;
}
lineHeight = Math.max(lineHeight, buttonSize.getHeight());
requiredSize.ensureWidth(lineWidth);
}
requiredSize.extendHeight(lineHeight + ViewConstants.VPADDING);
return requiredSize;
}