Search in sources :

Example 1 with GuiElement

use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.

the class AbstractGuiResourceLoadingList method load.

@Override
public void load() {
    // Stop current loading
    if (loaderThread != null) {
        loaderThread.interrupt();
        try {
            loaderThread.join();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return;
        }
    }
    // Clear list
    resourcesQueue.clear();
    for (GuiElement element : new ArrayList<>(resourcesPanel.getChildren())) {
        resourcesPanel.removeElement(element);
    }
    selected.clear();
    onSelectionChanged();
    // Load new data
    loaderThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                onLoad.consume(new Consumer<Supplier<U>>() {

                    @Override
                    public void consume(final Supplier<U> obj) {
                        resourcesQueue.offer(new Runnable() {

                            @Override
                            public void run() {
                                resourcesPanel.addElements(null, new Element(obj.get()));
                                resourcesPanel.sortElements();
                            }
                        });
                    }
                });
            } finally {
                resourcesQueue.offer(new Runnable() {

                    @Override
                    public void run() {
                        getListPanel().removeElement(loadingElement);
                    }
                });
            }
        }
    });
    getListPanel().addElements(new VerticalLayout.Data(0.5), loadingElement);
    loaderThread.start();
}
Also used : GuiElement(de.johni0702.minecraft.gui.element.GuiElement) ArrayList(java.util.ArrayList) VerticalLayout(de.johni0702.minecraft.gui.layout.VerticalLayout) Supplier(java.util.function.Supplier) GuiElement(de.johni0702.minecraft.gui.element.GuiElement)

Example 2 with GuiElement

use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.

the class VerticalLayout method calcMinSize.

@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    int maxWidth = 0;
    int height = 0;
    int spacing = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        height += spacing;
        spacing = this.spacing;
        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();
        int width = minSize.getWidth();
        if (width > maxWidth) {
            maxWidth = width;
        }
        height += minSize.getHeight();
    }
    return new Dimension(maxWidth, height);
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 3 with GuiElement

use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.

the class CustomLayout method layOut.

@Override
@SuppressWarnings("unchecked")
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer container, ReadableDimension size) {
    result.clear();
    if (parent == null) {
        Collection<GuiElement> elements = container.getChildren();
        for (GuiElement element : elements) {
            result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getMinSize())));
        }
    } else {
        Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> elements = parent.layOut(container, size);
        for (Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> entry : elements.entrySet()) {
            Pair<ReadablePoint, ReadableDimension> pair = entry.getValue();
            result.put(entry.getKey(), Pair.of(new Point(pair.getLeft()), new Dimension(pair.getRight())));
        }
    }
    layout((T) container, size.getWidth(), size.getHeight());
    return (Map) result;
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with GuiElement

use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.

the class GridLayout method calcNeededCellSize.

private Pair<int[], int[]> calcNeededCellSize(GuiContainer<?> container) {
    int[] columnMaxWidth = new int[columns];
    int[] rowMaxHeight = new int[(container.getElements().size() - 1 + columns) / columns];
    int elements = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        int column = elements % columns;
        int row = elements / columns;
        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();
        int width = minSize.getWidth();
        if (width > columnMaxWidth[column]) {
            columnMaxWidth[column] = width;
        }
        int height = minSize.getHeight();
        if (height > rowMaxHeight[row]) {
            rowMaxHeight[row] = height;
        }
        elements++;
    }
    return Pair.of(columnMaxWidth, rowMaxHeight);
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 5 with GuiElement

use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.

the class GridLayout method calcMinSize.

@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    Preconditions.checkState(columns != 0, "Columns may not be 0.");
    int maxWidth = 0, maxHeight = 0;
    int elements = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();
        int width = minSize.getWidth();
        if (width > maxWidth) {
            maxWidth = width;
        }
        int height = minSize.getHeight();
        if (height > maxHeight) {
            maxHeight = height;
        }
        elements++;
    }
    int rows = (elements - 1 + columns) / columns;
    int totalWidth = maxWidth * columns;
    int totalHeight = maxHeight * rows;
    if (!cellsEqualSize) {
        Pair<int[], int[]> maxCellSize = calcNeededCellSize(container);
        totalWidth = 0;
        for (int w : maxCellSize.getLeft()) {
            totalWidth += w;
        }
        totalHeight = 0;
        for (int h : maxCellSize.getRight()) {
            totalHeight += h;
        }
    }
    if (elements > 0) {
        totalWidth += spacingX * (columns - 1);
    }
    if (elements > columns) {
        totalHeight += spacingY * (rows - 1);
    }
    return new Dimension(totalWidth, totalHeight);
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Aggregations

GuiElement (de.johni0702.minecraft.gui.element.GuiElement)15 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)14 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)13 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)10 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)9 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 Pair (org.apache.commons.lang3.tuple.Pair)6 CrashException (net.minecraft.util.crash.CrashException)4 CrashReport (net.minecraft.util.crash.CrashReport)4 CrashReportSection (net.minecraft.util.crash.CrashReportSection)4 OffsetGuiRenderer (de.johni0702.minecraft.gui.OffsetGuiRenderer)3 AbstractComposedGuiElement (de.johni0702.minecraft.gui.element.AbstractComposedGuiElement)3 ComposedGuiElement (de.johni0702.minecraft.gui.element.ComposedGuiElement)3 RenderInfo (de.johni0702.minecraft.gui.RenderInfo)2 VerticalLayout (de.johni0702.minecraft.gui.layout.VerticalLayout)2 GuiRenderer (de.johni0702.minecraft.gui.GuiRenderer)1 GuiButton (de.johni0702.minecraft.gui.element.GuiButton)1 GuiDropdownMenu (de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu)1 File (java.io.File)1