Search in sources :

Example 1 with Layout

use of com.badlogic.gdx.scenes.scene2d.utils.Layout in project libgdx by libgdx.

the class VerticalGroup method layout.

public void layout() {
    if (sizeInvalid)
        computeSize();
    if (wrap) {
        layoutWrapped();
        return;
    }
    boolean round = this.round;
    int align = this.align;
    float space = this.space, padLeft = this.padLeft, fill = this.fill;
    float columnWidth = (expand ? getWidth() : prefWidth) - padLeft - padRight, y = prefHeight - padTop + space;
    if ((align & Align.top) != 0)
        y += getHeight() - prefHeight;
    else if (// center
    (align & Align.bottom) == 0)
        y += (getHeight() - prefHeight) / 2;
    float startX;
    if ((align & Align.left) != 0)
        startX = padLeft;
    else if ((align & Align.right) != 0)
        startX = getWidth() - padRight - columnWidth;
    else
        startX = padLeft + (getWidth() - padLeft - padRight - columnWidth) / 2;
    align = columnAlign;
    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 (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 = startX;
        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 : Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 2 with Layout

use of com.badlogic.gdx.scenes.scene2d.utils.Layout in project libgdx by libgdx.

the class Widget method invalidateHierarchy.

public void invalidateHierarchy() {
    if (!layoutEnabled)
        return;
    invalidate();
    Group parent = getParent();
    if (parent instanceof Layout)
        ((Layout) parent).invalidateHierarchy();
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout)

Example 3 with Layout

use of com.badlogic.gdx.scenes.scene2d.utils.Layout in project libgdx by libgdx.

the class Stack method layout.

public void layout() {
    if (sizeInvalid)
        computeSize();
    float width = getWidth(), height = getHeight();
    Array<Actor> children = getChildren();
    for (int i = 0, n = children.size; i < n; i++) {
        Actor child = children.get(i);
        child.setBounds(0, 0, width, height);
        if (child instanceof Layout)
            ((Layout) child).validate();
    }
}
Also used : Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 4 with Layout

use of com.badlogic.gdx.scenes.scene2d.utils.Layout in project libgdx by libgdx.

the class HorizontalGroup method computeSize.

private void computeSize() {
    sizeInvalid = false;
    SnapshotArray<Actor> children = getChildren();
    int n = children.size;
    prefHeight = 0;
    if (wrap) {
        prefWidth = 0;
        if (rowSizes == null)
            rowSizes = new FloatArray();
        else
            rowSizes.clear();
        FloatArray rowSizes = this.rowSizes;
        float space = this.space, wrapSpace = this.wrapSpace;
        float pad = padLeft + padRight, groupWidth = getWidth() - pad, x = 0, y = 0, rowHeight = 0;
        int i = 0, incr = 1;
        if (reverse) {
            i = n - 1;
            n = -1;
            incr = -1;
        }
        for (; i != n; i += incr) {
            Actor child = children.get(i);
            float width, height;
            if (child instanceof Layout) {
                Layout layout = (Layout) child;
                width = layout.getPrefWidth();
                height = layout.getPrefHeight();
            } else {
                width = child.getWidth();
                height = child.getHeight();
            }
            float incrX = width + (x > 0 ? space : 0);
            if (x + incrX > groupWidth && x > 0) {
                rowSizes.add(x);
                rowSizes.add(rowHeight);
                prefWidth = Math.max(prefWidth, x + pad);
                if (y > 0)
                    y += wrapSpace;
                y += rowHeight;
                rowHeight = 0;
                x = 0;
                incrX = width;
            }
            x += incrX;
            rowHeight = Math.max(rowHeight, height);
        }
        rowSizes.add(x);
        rowSizes.add(rowHeight);
        prefWidth = Math.max(prefWidth, x + pad);
        if (y > 0)
            y += wrapSpace;
        prefHeight = Math.max(prefHeight, y + rowHeight);
    } else {
        prefWidth = padLeft + padRight + space * (n - 1);
        for (int i = 0; i < n; i++) {
            Actor child = children.get(i);
            if (child instanceof Layout) {
                Layout layout = (Layout) child;
                prefWidth += layout.getPrefWidth();
                prefHeight = Math.max(prefHeight, layout.getPrefHeight());
            } else {
                prefWidth += child.getWidth();
                prefHeight = Math.max(prefHeight, child.getHeight());
            }
        }
    }
    prefHeight += padTop + padBottom;
    if (round) {
        prefWidth = Math.round(prefWidth);
        prefHeight = Math.round(prefHeight);
    }
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 5 with Layout

use of com.badlogic.gdx.scenes.scene2d.utils.Layout in project libgdx by libgdx.

the class HorizontalGroup method layoutWrapped.

private void layoutWrapped() {
    float prefHeight = getPrefHeight();
    if (prefHeight != lastPrefHeight) {
        lastPrefHeight = prefHeight;
        invalidateHierarchy();
    }
    int align = this.align;
    boolean round = this.round;
    float space = this.space, padBottom = this.padBottom, fill = this.fill, wrapSpace = this.wrapSpace;
    float maxWidth = prefWidth - padLeft - padRight;
    float rowY = prefHeight - padTop, groupWidth = getWidth(), xStart = padLeft, x = 0, rowHeight = 0;
    if ((align & Align.top) != 0)
        rowY += getHeight() - prefHeight;
    else if (// center
    (align & Align.bottom) == 0)
        rowY += (getHeight() - prefHeight) / 2;
    if ((align & Align.right) != 0)
        xStart += groupWidth - prefWidth;
    else if (// center
    (align & Align.left) == 0)
        xStart += (groupWidth - prefWidth) / 2;
    groupWidth -= padRight;
    align = this.rowAlign;
    FloatArray rowSizes = this.rowSizes;
    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 (x + width > groupWidth || r == 0) {
            x = xStart;
            if ((align & Align.right) != 0)
                x += maxWidth - rowSizes.get(r);
            else if (// center
            (align & Align.left) == 0)
                x += (maxWidth - rowSizes.get(r)) / 2;
            rowHeight = rowSizes.get(r + 1);
            if (r > 0)
                rowY -= wrapSpace;
            rowY -= rowHeight;
            r += 2;
        }
        if (fill > 0)
            height = rowHeight * fill;
        if (layout != null) {
            height = Math.max(height, layout.getMinHeight());
            float maxHeight = layout.getMaxHeight();
            if (maxHeight > 0 && height > maxHeight)
                height = maxHeight;
        }
        float y = rowY;
        if ((align & Align.top) != 0)
            y += rowHeight - height;
        else if (// center
        (align & Align.bottom) == 0)
            y += (rowHeight - height) / 2;
        if (round)
            child.setBounds(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
        else
            child.setBounds(x, y, width, height);
        x += width + space;
        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

Layout (com.badlogic.gdx.scenes.scene2d.utils.Layout)14 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 FloatArray (com.badlogic.gdx.utils.FloatArray)4 Group (com.badlogic.gdx.scenes.scene2d.Group)2 Rectangle (com.badlogic.gdx.math.Rectangle)1 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)1