Search in sources :

Example 11 with FloatArray

use of com.badlogic.gdx.utils.FloatArray in project libgdx by libgdx.

the class VerticalGroup method layoutWrapped.

private void layoutWrapped() {
    float prefWidth = getPrefWidth();
    if (prefWidth != lastPrefWidth) {
        lastPrefWidth = prefWidth;
        invalidateHierarchy();
    }
    int align = this.align;
    boolean round = this.round;
    float space = this.space, padLeft = this.padLeft, fill = this.fill, wrapSpace = this.wrapSpace;
    float maxHeight = prefHeight - padTop - padBottom;
    float columnX = padLeft, groupHeight = getHeight();
    float yStart = prefHeight - padTop + space, y = 0, columnWidth = 0;
    if ((align & Align.right) != 0)
        columnX += getWidth() - prefWidth;
    else if (// center
    (align & Align.left) == 0)
        columnX += (getWidth() - prefWidth) / 2;
    if ((align & Align.top) != 0)
        yStart += groupHeight - prefHeight;
    else if (// center
    (align & Align.bottom) == 0)
        yStart += (groupHeight - prefHeight) / 2;
    groupHeight -= padTop;
    align = columnAlign;
    FloatArray columnSizes = this.columnSizes;
    SnapshotArray<Actor> children = getChildren();
    int i = 0, n = children.size, incr = 1;
    if (reverse) {
        i = n - 1;
        n = -1;
        incr = -1;
    }
    for (int r = 0; i != n; i += incr) {
        Actor child = children.get(i);
        float width, height;
        Layout layout = null;
        if (child instanceof Layout) {
            layout = (Layout) child;
            width = layout.getPrefWidth();
            height = layout.getPrefHeight();
        } else {
            width = child.getWidth();
            height = child.getHeight();
        }
        if (y - height - space < padBottom || r == 0) {
            y = yStart;
            if ((align & Align.bottom) != 0)
                y -= maxHeight - columnSizes.get(r);
            else if (// center
            (align & Align.top) == 0)
                y -= (maxHeight - columnSizes.get(r)) / 2;
            if (r > 0) {
                columnX += wrapSpace;
                columnX += columnWidth;
            }
            columnWidth = columnSizes.get(r + 1);
            r += 2;
        }
        if (fill > 0)
            width = columnWidth * fill;
        if (layout != null) {
            width = Math.max(width, layout.getMinWidth());
            float maxWidth = layout.getMaxWidth();
            if (maxWidth > 0 && width > maxWidth)
                width = maxWidth;
        }
        float x = columnX;
        if ((align & Align.right) != 0)
            x += columnWidth - width;
        else if (// center
        (align & Align.left) == 0)
            x += (columnWidth - width) / 2;
        y -= height + space;
        if (round)
            child.setBounds(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
        else
            child.setBounds(x, y, width, height);
        if (layout != null)
            layout.validate();
    }
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Aggregations

FloatArray (com.badlogic.gdx.utils.FloatArray)11 Actor (com.badlogic.gdx.scenes.scene2d.Actor)4 Layout (com.badlogic.gdx.scenes.scene2d.utils.Layout)4 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)2 GlyphRun (com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun)2 IntArray (com.badlogic.gdx.utils.IntArray)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 BitmapFontData (com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 TextArea (com.badlogic.gdx.scenes.scene2d.ui.TextArea)1