if (xPos != widthStart) {
if (!atRowStart) {
    protected Vector2f calcLayout(WidgetContainerAbstract parent, boolean setPosSize) {        Vector2f ret = new Vector2f();        if (parent.isVisible() == false)            return ret;        int totalChildren = parent.getWidgetCount();        if (totalChildren > 0) {            Widget child;            Vector2f size;            boolean pastWidth;            boolean pastMaxWidth;            boolean pastParentWidth;            boolean lastChild;            boolean atRowStart;            WidgetInsets insets = parent.getInsets();            WidgetBorder border = parent.getBorder();            float parentWidth = parent.getWidth();            float parentHeight = parent.getHeight();            float widthStart = 0;            float curWidth = widthStart;            float heightStart = parentHeight - (border.getTop() + insets.getTop());            float maxRowHeight = 0;            float xPos = widthStart;            float yPos = heightStart;            int idx;            int rowStartIdx;            ArrayList preferredSizes = new ArrayList();            ArrayList newBounds = new ArrayList();            WidgetBoundingRectangle r;            for (idx = 0; idx < totalChildren; idx++) {                child = parent.getWidget(idx);                size = child.getPreferredSize();                if (setPosSize == true) {                    if (fillType == WidgetFillType.HORIZONTAL) {                        size.x = parentWidth;                    } else if (fillType == WidgetFillType.VERTICAL) {                        size.y = parentHeight;                    } else if (fillType == WidgetFillType.VERTICAL_HORIZONTAL) {                        size.x = parentWidth;                        size.y = parentHeight;                    }                }                preferredSizes.add(size);                r = new WidgetBoundingRectangle();                r.setSize(size);                newBounds.add(r);            }            for (idx = rowStartIdx = 0; idx < totalChildren; idx++) {                if (curWidth != widthStart) {                    curWidth += hgap;                }                child = parent.getWidget(idx);                if (child.isVisible()) {                    size = (Vector2f) preferredSizes.get(idx);                    r = (WidgetBoundingRectangle) newBounds.get(idx);                    curWidth += size.x;                    pastMaxWidth = (maximumSize.x > 0 && maximumSize.x < curWidth);                    pastParentWidth = (!pastMaxWidth && wrap && parentWidth > 0 && parentWidth < curWidth);                                        pastWidth = pastMaxWidth || pastParentWidth;                                        lastChild = (idx + 1 == totalChildren);                    atRowStart = (xPos == widthStart);                    if ((!pastWidth || atRowStart) && size.y > maxRowHeight) {                        maxRowHeight = size.y;                    }                                       if (pastWidth || lastChild) {                                                /*                          * Passed max width                          * OR                         * Passe width of the parent                         * OR                         * Last child                         */                        if ((!atRowStart && pastWidth)) {                            /*                              * Not the first child on a row                             * AND                             * Not the last child                             * SO                             * process this child again                             */                            idx--;                        } else if (atRowStart || lastChild) {                            /*                             * First child on a row                             * OR                             * Last child                             */                            r.setMinXPreserveSize(xPos); //Set the x location (left)                        }                        /*                         * Set height and y position                         */                        yPos -= maxRowHeight;                        for (int i = rowStartIdx; i <= idx; i++) {                            r = (WidgetBoundingRectangle) newBounds.get(i);                            r.setMinYPreserveSize(yPos); //Set y location (bottom)                            /*                             * Set size to preferred width and max row height                             */                            r.setHeight(maxRowHeight);                        }                        if (idx + 1 != totalChildren) {                            /*                             * NOT the last child                             * SO                             * Setup for a new row                             */                            xPos = curWidth = widthStart;                            if (yPos != heightStart) { //NOT first row                                yPos -= vgap; //Add vertical gap                            }                            rowStartIdx = idx + 1;                            maxRowHeight = 0;                        } else {                            /*                             * Last child                             * SO                             * Stop                             */                            break;                        }                    } else {                        /*                         * NOT passed max width                         * AND                         * NOT last child                         */                        r.setMinXPreserveSize(xPos); //Set the x location (left)                        if (xPos != widthStart) { //NOT first in row                            xPos += hgap; //Add horizontal gap                        }                        xPos += size.x;                    }                }            }            WidgetBoundingRectangle bounds = new WidgetBoundingRectangle((WidgetBoundingRectangle) newBounds.get(0));            for (idx = 0; idx < totalChildren; idx++) {                child = parent.getWidget(idx);                if (child.isVisible()) {                    r = (WidgetBoundingRectangle) newBounds.get(idx);                    bounds = (WidgetBoundingRectangle) bounds.merge(r);                    if (setPosSize == true) {                        Vector2f l = r.getMin();                        Vector2f s = r.getSize();                                                // TODO:  Handle alignment here    //                        if (this.alignmentType == WidgetAlignmentType.ALIGN_CENTER)//                            l.x = (int) (l.x + (parentWidth.x - rWidth) / 2);//                        else if (this.alignmentType == WidgetAlignmentType.ALIGN_EAST)//                            leftPos = (int) (x + (parentDim.x - rWidth));                                                child.setLocation(l);                        child.setSize(s);                    }                }                ret.x = bounds.getWidth();                ret.y = bounds.getHeight();            }        }        return ret;    }