Example usage for com.badlogic.gdx.scenes.scene2d.utils Layout getMinWidth

List of usage examples for com.badlogic.gdx.scenes.scene2d.utils Layout getMinWidth

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.utils Layout getMinWidth.

Prototype

public float getMinWidth();

Source Link

Usage

From source file:net.dermetfan.gdx.scenes.scene2d.ui.CircularGroup.java

License:Apache License

/** computes {@link #cachedMinWidth}, {@link #cachedMinHeight}, {@link #cachedPrefWidth} and {@link #cachedPrefHeight} */
protected void computeSize() {
    cachedMinWidth = cachedMinHeight = Float.POSITIVE_INFINITY;
    cachedPrefWidth = cachedPrefHeight = 0;

    SnapshotArray<Actor> children = getChildren();
    for (int index = 0; index < children.size; index++) {
        Actor child = children.get(index);

        // find child size
        float minWidth, minHeight, prefWidth, prefHeight;
        if (child instanceof Layout) {
            Layout layout = (Layout) child;
            minWidth = layout.getMinWidth();
            minHeight = layout.getMinHeight();
            prefWidth = layout.getPrefWidth();
            prefHeight = layout.getPrefHeight();
        } else {/*from  w ww . ja  va  2 s  .co m*/
            minWidth = prefWidth = child.getWidth();
            minHeight = prefHeight = child.getHeight();
        }

        // anchor offset and local anchor
        tmp.set(modifier.anchorOffset(tmp.setZero(), child, index, children.size, this));
        float offsetX = tmp.x, offsetY = tmp.y;
        tmp.set(modifier.localAnchor(tmp.set(minWidth, minHeight / 2), child, index, children.size, this))
                .sub(offsetX, offsetY);
        if (tmp.x < minWidth || tmp.x < 0)
            minWidth -= tmp.x;
        else
            minWidth += tmp.x - minWidth;
        if (tmp.y < minHeight || tmp.y < 0)
            minHeight -= tmp.y;
        else
            minHeight += tmp.y - minHeight;
        tmp.set(modifier.localAnchor(tmp.set(prefWidth, prefHeight / 2), child, index, children.size, this))
                .sub(offsetX, offsetY);
        if (tmp.x < prefWidth || tmp.x < 0)
            prefWidth -= tmp.x;
        else
            prefWidth += tmp.x - prefWidth;
        if (tmp.y < prefHeight || tmp.y < 0)
            prefHeight -= tmp.y;
        else
            prefHeight += tmp.y - prefHeight;

        // update caches
        if (minWidth < cachedMinWidth)
            cachedMinWidth = minWidth;
        if (minHeight < cachedMinHeight)
            cachedMinHeight = minHeight;
        if (prefWidth > cachedPrefWidth)
            cachedPrefWidth = prefWidth;
        if (prefHeight > cachedPrefHeight)
            cachedPrefHeight = prefHeight;
    }

    cachedMinWidth *= 2;
    cachedMinHeight *= 2;
    cachedPrefWidth *= 2;
    cachedPrefHeight *= 2;

    // ensure circle
    cachedMinWidth = cachedMinHeight = Math.max(cachedMinWidth, cachedMinHeight);
    cachedPrefWidth = cachedPrefHeight = Math.max(cachedPrefWidth, cachedPrefHeight);

    sizeInvalid = false;
}

From source file:net.dermetfan.gdx.scenes.scene2d.ui.CircularGroup.java

License:Apache License

@Override
public void layout() {
    float prefWidthUnderflow = shrinkChildren ? Math.max(0, getPrefWidth() - getWidth()) / 2 : 0,
            prefHeightUnderflow = shrinkChildren ? Math.max(0, getPrefHeight() - getHeight()) / 2 : 0;
    SnapshotArray<Actor> children = getChildren();
    for (int index = 0; index < children.size; index++) {
        Actor child = children.get(index);

        // get dimensions and resize
        float width, height;
        if (child instanceof Layout) {
            Layout childLayout = (Layout) child;
            width = childLayout.getPrefWidth() - prefWidthUnderflow;
            width = Math.max(width, childLayout.getMinWidth());
            if (childLayout.getMaxWidth() != 0)
                width = Math.min(width, childLayout.getMaxWidth());
            height = childLayout.getPrefHeight() - prefHeightUnderflow;
            height = Math.max(height, childLayout.getMinHeight());
            if (childLayout.getMaxHeight() != 0)
                height = Math.min(height, childLayout.getMaxHeight());
            child.setSize(width, height);
            childLayout.validate();//ww  w . ja va 2 s .co  m
        } else {
            width = child.getWidth();
            height = child.getHeight();
        }

        float angle = fullAngle / (children.size - (virtualChildEnabled ? 0 : 1)) * index;
        angle += angleOffset;
        angle = modifier.angle(angle, child, index, children.size, this);

        float rotation = modifier.rotation(angle, child, index, children.size, this);

        tmp.set(modifier.anchorOffset(tmp.setZero(), child, index, children.size, this));
        tmp.rotate(angle);
        float offsetX = tmp.x, offsetY = tmp.y;

        tmp.set(modifier.localAnchor(tmp.set(width, height / 2), child, index, children.size, this));
        float localAnchorX = tmp.x, localAnchorY = tmp.y;

        child.setOrigin(localAnchorX, localAnchorY);
        child.setRotation(rotation);
        child.setPosition(getWidth() / 2 + offsetX - localAnchorX, getHeight() / 2 + offsetY - localAnchorY);
    }
}