Search in sources :

Example 16 with UIWidget

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

the class CanvasImpl method addInteractionRegion.

@Override
public void addInteractionRegion(InteractionListener listener, String tooltip, Rect2i region) {
    UIWidget tooltipLabelWidget = (tooltip == null || tooltip.isEmpty()) ? null : new UILabel(tooltip);
    addInteractionRegion(listener, tooltipLabelWidget, region);
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 17 with UIWidget

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

the class NUIManagerInternal method addOverlay.

@Override
public <T extends ControlWidget> T addOverlay(ResourceUrn overlayUri, Class<T> expectedType) {
    boolean existsAlready = assetManager.isLoaded(overlayUri, UIElement.class);
    Optional<UIElement> opt = Assets.get(overlayUri, UIElement.class);
    if (!opt.isPresent()) {
        logger.error("Can't find overlay '{}'", overlayUri);
    } else {
        UIElement element = opt.get();
        UIWidget root = element.getRootWidget();
        if (expectedType.isInstance(root)) {
            T overlay = expectedType.cast(root);
            if (!existsAlready) {
                initialiseOverlay(overlay, overlayUri);
            }
            addOverlay(overlay, overlayUri);
            return overlay;
        } else {
            logger.error("Screen '{}' is a '{}' and not a '{}'", overlayUri, root.getClass(), expectedType);
        }
    }
    return null;
}
Also used : UIElement(org.terasology.rendering.nui.asset.UIElement) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 18 with UIWidget

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

the class ColumnLayout method calculateRowSize.

private RowInfo calculateRowSize(List<UIWidget> row, Canvas canvas, Vector2i areaHint) {
    int availableWidth = areaHint.x - horizontalSpacing * (columns - 1);
    RowInfo rowInfo = new RowInfo();
    for (int i = 0; i < columns && i < row.size(); ++i) {
        UIWidget widget = row.get(i);
        Vector2i cellSize = new Vector2i(availableWidth, areaHint.y);
        if (!autoSizeColumns) {
            cellSize.x *= columnWidths[i];
        }
        if (widget != null) {
            Vector2i contentSize = canvas.calculateRestrictedSize(widget, cellSize);
            rowInfo.widgetSizes.add(contentSize);
            rowInfo.height = Math.max(rowInfo.height, contentSize.y);
        } else {
            rowInfo.widgetSizes.add(new Vector2i(0, 0));
        }
    }
    return rowInfo;
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 19 with UIWidget

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

the class ColumnLayout method getMaxContentSize.

@Override
public Vector2i getMaxContentSize(Canvas canvas) {
    Iterator<List<UIWidget>> rows = getRowIterator();
    Vector2i size = new Vector2i();
    int[] columnSizes = new int[columns];
    while (rows.hasNext()) {
        List<UIWidget> row = rows.next();
        int rowHeight = 0;
        for (int i = 0; i < row.size(); ++i) {
            Vector2i maxSize = canvas.calculateMaximumSize(row.get(i));
            columnSizes[i] = Math.max(columnSizes[i], maxSize.x);
            rowHeight = Math.max(rowHeight, maxSize.y);
        }
        size.y = TeraMath.addClampAtMax(size.y, rowHeight);
        if (rows.hasNext()) {
            size.y = TeraMath.addClampAtMax(size.y, verticalSpacing);
        }
    }
    long width = 0;
    for (int columnSize : columnSizes) {
        width += columnSize;
    }
    if (!autoSizeColumns) {
        for (int i = 0; i < columns; ++i) {
            width = Math.min(width, TeraMath.floorToInt(columnSizes[i] / columnWidths[i]));
        }
    }
    width += horizontalSpacing * (columns - 1);
    size.x = (int) Math.min(Integer.MAX_VALUE, width);
    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 20 with UIWidget

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

the class MultiRowLayout method onDraw.

@Override
public void onDraw(Canvas canvas) {
    if (!widgetList.isEmpty()) {
        Vector2i availableSize = canvas.size();
        int numColumns = TeraMath.ceilToInt((float) widgetList.size() / rows);
        if (numColumns > 0) {
            availableSize.x -= horizontalSpacing * (numColumns - 1);
        }
        if (rows > 0) {
            availableSize.y -= verticalSpacing * (rows - 1);
        }
        List<List<UIWidget>> columns = Lists.newArrayList(getColumnIterator());
        List<ColumnInfo> columnInfos = Lists.newArrayList();
        columnInfos.addAll(columns.stream().map(column -> calculateColumnSize(column, canvas, availableSize)).collect(Collectors.toList()));
        int[] minHeights = new int[rows];
        int minColumnHeight = 0;
        int columnOffsetY = 0;
        if (autoSizeRows) {
            for (ColumnInfo column : columnInfos) {
                for (int row = 0; row < column.widgetSizes.size(); row++) {
                    minHeights[row] = Math.max(minHeights[row], column.widgetSizes.get(row).getY());
                }
            }
            for (int height : minHeights) {
                minColumnHeight += height;
            }
            minColumnHeight += (rows - 1) * verticalSpacing;
            columnOffsetY = (canvas.size().y - minColumnHeight) / 2;
        } else {
            minColumnHeight = canvas.size().y;
            for (int i = 0; i < rows; ++i) {
                minHeights[i] = TeraMath.floorToInt((minColumnHeight - (rows - 1) * verticalSpacing) * rowHeights[i]);
            }
        }
        int columnOffsetX = 0;
        int usedWidth = 0;
        for (ColumnInfo column : columnInfos) {
            usedWidth += column.width;
        }
        usedWidth += (columnInfos.size() - 1) * horizontalSpacing;
        columnOffsetX = (canvas.size().x - usedWidth) / 2;
        for (int columnIndex = 0; columnIndex < columns.size(); ++columnIndex) {
            List<UIWidget> column = columns.get(columnIndex);
            ColumnInfo columnInfo = columnInfos.get(columnIndex);
            int cellOffsetY = columnOffsetY;
            for (int i = 0; i < column.size(); ++i) {
                UIWidget widget = column.get(i);
                int columnWidth = columnInfo.width;
                if (widget != null) {
                    Rect2i drawRegion = Rect2i.createFromMinAndSize(columnOffsetX, cellOffsetY, columnWidth, minHeights[i]);
                    canvas.drawWidget(widget, drawRegion);
                }
                cellOffsetY += minHeights[i] + verticalSpacing;
            }
            columnOffsetX += columnInfo.width + horizontalSpacing;
        }
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) List(java.util.List) Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) 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