@Override
	protected void layoutSelf(Rectangle bounds) {
		createGrid(LayoutSize.PREFERRED);

		// Size widths appropriately
		int[] x = new int[mColumns];
		int width = updateStarts(bounds.x, mColumnWidths, x);
		int extra = bounds.width - width;
		if (extra != 0) {
			if (extra > 0) {
				grow(extra, mColumnWidths, mMaxColumnWidths, getFillHorizontal());
			} else {
				shrink(-extra, mColumnWidths, mMinColumnWidths);
			}
			width = updateStarts(bounds.x, mColumnWidths, x);
		}

		// Size heights appropriately
		int[] y = new int[mRows];
		int height = updateStarts(bounds.y, mRowHeights, y);
		extra = bounds.height - height;
		if (extra != 0) {
			if (extra > 0) {
				grow(extra, mRowHeights, mMaxRowHeights, getFillVertical());
			} else {
				shrink(-extra, mRowHeights, mMinRowHeights);
			}
			height = updateStarts(bounds.y, mRowHeights, y);
		}

		// Set the child bounds
		ArrayList<Rectangle> cellBounds = new ArrayList<>(getChildCount());
		for (FlexCell cell : getChildren()) {
			FlexGridData data = mData.get(cell);
			Rectangle rect = new Rectangle();
			rect.x = x[data.mColumn];
			rect.y = y[data.mRow];
			int last = data.getLastColumn();
			width = 0;
			for (int column = data.mColumn; column <= last; column++) {
				width += mColumnWidths[column];
			}
			rect.width = width;
			last = data.getLastRow();
			height = 0;
			for (int row = data.mRow; row <= last; row++) {
				height += mRowHeights[row];
			}
			rect.height = height;
			cellBounds.add(rect);
		}
		flush();
		layoutChildren(cellBounds.toArray(new Rectangle[cellBounds.size()]));
	}