Search in sources :

Example 6 with UIWidget

use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.

the class FlowLayout method getPreferredContentSize.

@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) {
    Vector2i result = new Vector2i();
    int filledWidth = 0;
    int filledHeight = 0;
    for (UIWidget widget : contents) {
        Vector2i size = canvas.calculatePreferredSize(widget);
        if (filledWidth != 0 && filledWidth + size.x > sizeHint.x) {
            result.x = Math.max(result.x, filledWidth);
            result.y += filledHeight;
            filledWidth = size.x;
            filledHeight = size.y;
        } else {
            filledWidth += size.x;
            filledHeight = Math.max(filledHeight, size.y);
        }
    }
    result.x = Math.max(result.x, filledWidth);
    result.y += filledHeight;
    return result;
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 7 with UIWidget

use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.

the class FlowLayout method onDraw.

@Override
public void onDraw(Canvas canvas) {
    int filledWidth = 0;
    int filledHeight = 0;
    int heightOffset = 0;
    for (UIWidget widget : contents) {
        Vector2i size = canvas.calculatePreferredSize(widget);
        if (filledWidth != 0 && filledWidth + size.x > canvas.size().x) {
            heightOffset += filledHeight;
            filledWidth = 0;
            filledHeight = 0;
        }
        canvas.drawWidget(widget, Rect2i.createFromMinAndSize(filledWidth, heightOffset, size.x, size.y));
        filledWidth += size.x;
        filledHeight = Math.max(filledHeight, size.y);
    }
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 8 with UIWidget

use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.

the class MultiRowLayout method getMaxContentSize.

@Override
public Vector2i getMaxContentSize(Canvas canvas) {
    Iterator<List<UIWidget>> columns = getColumnIterator();
    Vector2i size = new Vector2i();
    int[] rowSizes = new int[rows];
    while (columns.hasNext()) {
        List<UIWidget> column = columns.next();
        int columnWidth = 0;
        for (int i = 0; i < column.size(); ++i) {
            Vector2i maxSize = canvas.calculateMaximumSize(column.get(i));
            rowSizes[i] = Math.max(rowSizes[i], maxSize.y);
            columnWidth = Math.max(columnWidth, maxSize.x);
        }
        size.x = TeraMath.addClampAtMax(size.x, columnWidth);
        if (columns.hasNext()) {
            size.x = TeraMath.addClampAtMax(size.x, horizontalSpacing);
        }
    }
    long height = 0;
    for (int rowSize : rowSizes) {
        height += rowSize;
    }
    if (!autoSizeRows) {
        for (int i = 0; i < rows; ++i) {
            height = Math.min(height, TeraMath.floorToInt(rowSizes[i] / rowHeights[i]));
        }
    }
    height += verticalSpacing * (rows - 1);
    size.y = (int) Math.min(Integer.MAX_VALUE, height);
    return size;
}
Also used : List(java.util.List) Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 9 with UIWidget

use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.

the class MultiRowLayout method getPreferredContentSize.

@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) {
    Vector2i availableSize = new Vector2i(areaHint);
    int numColumns = TeraMath.ceilToInt((float) widgetList.size() / rows);
    if (numColumns > 0) {
        availableSize.x -= horizontalSpacing * (numColumns - 1);
    }
    if (rows > 0) {
        availableSize.y -= verticalSpacing * (rows - 1);
    }
    Iterator<List<UIWidget>> columns = getColumnIterator();
    Vector2i size = new Vector2i();
    int[] rowSizes = new int[rows];
    while (columns.hasNext()) {
        List<UIWidget> column = columns.next();
        ColumnInfo columnInfo = calculateColumnSize(column, canvas, availableSize);
        size.x += columnInfo.width;
        if (columns.hasNext()) {
            size.x += horizontalSpacing;
        }
        for (int i = 0; i < columnInfo.widgetSizes.size(); ++i) {
            rowSizes[i] = Math.max(rowSizes[i], columnInfo.widgetSizes.get(i).getY());
        }
    }
    for (int rowSize : rowSizes) {
        size.y += rowSize;
    }
    if (!autoSizeRows) {
        for (int i = 0; i < rows; ++i) {
            size.y = Math.max(size.y, TeraMath.floorToInt(rowSizes[i] / rowHeights[i]));
        }
    }
    size.y += verticalSpacing * (rows - 1);
    return size;
}
Also used : List(java.util.List) Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 10 with UIWidget

use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.

the class PropertyLayout method expand.

private void expand(Collection<Property<?, ?>> properties, MigLayout layout) {
    List<Property<?, ?>> props = Lists.newArrayList(properties);
    Collections.sort(props, propertyComparator);
    for (Property<?, ?> property : props) {
        UILabel label = property.getLabel();
        UIWidget editor = property.getEditor();
        editor.setTooltip(property.getDescription());
        layout.addWidget(label, new CCHint("newline"));
        layout.addWidget(editor, new CCHint());
    }
    invalidate();
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Property(org.terasology.rendering.nui.properties.Property) UIWidget(org.terasology.rendering.nui.UIWidget)

Aggregations

UIWidget (org.terasology.rendering.nui.UIWidget)23 Vector2i (org.terasology.math.geom.Vector2i)13 LayoutHint (org.terasology.rendering.nui.LayoutHint)12 List (java.util.List)6 UILabel (org.terasology.rendering.nui.widgets.UILabel)4 Rect2i (org.terasology.math.geom.Rect2i)3 UIElement (org.terasology.rendering.nui.asset.UIElement)3 JsonTree (org.terasology.rendering.nui.widgets.treeView.JsonTree)3 JsonElement (com.google.gson.JsonElement)2 UIFormat (org.terasology.rendering.nui.asset.UIFormat)2 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 TIntList (gnu.trove.list.TIntList)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ComponentWrapper (net.miginfocom.layout.ComponentWrapper)1 AssetDataFile (org.terasology.assets.format.AssetDataFile)1