// Path: src/main/java/de/johni0702/minecraft/gui/container/GuiContainer.java
// public interface GuiContainer<T extends GuiContainer<T>> extends ComposedGuiElement<T> {
// 
//     T setLayout(Layout layout);
//     Layout getLayout();
// 
//     void convertFor(GuiElement element, Point point);
// 
//     /**
//      * Converts the global coordinates of the point to ones relative to the element.
//      * @param element The element, must be part of this container
//      * @param point The point
//      * @param relativeLayer Layer at which the point is relative to this element,
//      *                      positive values are above this element
//      */
//     void convertFor(GuiElement element, Point point, int relativeLayer);
// 
//     Map<GuiElement, LayoutData> getElements();
//     T addElements(LayoutData layoutData, GuiElement... elements);
//     T removeElement(GuiElement element);
//     T sortElements();
//     T sortElements(Comparator<GuiElement> comparator);
// 
//     ReadableColor getBackgroundColor();
//     T setBackgroundColor(ReadableColor backgroundColor);
// }
// 
// Path: src/main/java/de/johni0702/minecraft/gui/element/GuiElement.java
// public interface GuiElement<T extends GuiElement<T>> {
// 
//     MinecraftClient getMinecraft();
// 
//     GuiContainer getContainer();
//     T setContainer(GuiContainer container);
// 
//     void layout(ReadableDimension size, RenderInfo renderInfo);
//     void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo);
// 
//     ReadableDimension getMinSize();
//     ReadableDimension getMaxSize();
// 
//     T setMaxSize(ReadableDimension maxSize);
// 
//     boolean isEnabled();
//     T setEnabled(boolean enabled);
//     T setEnabled();
//     T setDisabled();
// 
//     GuiElement getTooltip(RenderInfo renderInfo);
//     T setTooltip(GuiElement tooltip);
// 
//     /**
//      * Returns the layer this element takes part in.
//      * The standard layer is layer 0. Event handlers will be called for this layer.
//      * @return The layer of this element
//      */
//     int getLayer();
// 
// }


import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import com.google.common.base.Preconditions;
import de.johni0702.minecraft.gui.container.GuiContainer;
import de.johni0702.minecraft.gui.element.GuiElement;
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
import de.johni0702.minecraft.gui.utils.lwjgl.Point;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
            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);
    }

// Path: src/main/java/de/johni0702/minecraft/gui/container/GuiContainer.java
// public interface GuiContainer<T extends GuiContainer<T>> extends ComposedGuiElement<T> {
// 
//     T setLayout(Layout layout);
//     Layout getLayout();
// 
//     void convertFor(GuiElement element, Point point);
// 
//     /**
//      * Converts the global coordinates of the point to ones relative to the element.
//      * @param element The element, must be part of this container
//      * @param point The point
//      * @param relativeLayer Layer at which the point is relative to this element,
//      *                      positive values are above this element
//      */
//     void convertFor(GuiElement element, Point point, int relativeLayer);
// 
//     Map<GuiElement, LayoutData> getElements();
//     T addElements(LayoutData layoutData, GuiElement... elements);
//     T removeElement(GuiElement element);
//     T sortElements();
//     T sortElements(Comparator<GuiElement> comparator);
// 
//     ReadableColor getBackgroundColor();
//     T setBackgroundColor(ReadableColor backgroundColor);
// }
// 
// Path: src/main/java/de/johni0702/minecraft/gui/element/GuiElement.java
// public interface GuiElement<T extends GuiElement<T>> {
// 
//     MinecraftClient getMinecraft();
// 
//     GuiContainer getContainer();
//     T setContainer(GuiContainer container);
// 
//     void layout(ReadableDimension size, RenderInfo renderInfo);
//     void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo);
// 
//     ReadableDimension getMinSize();
//     ReadableDimension getMaxSize();
// 
//     T setMaxSize(ReadableDimension maxSize);
// 
//     boolean isEnabled();
//     T setEnabled(boolean enabled);
//     T setEnabled();
//     T setDisabled();
// 
//     GuiElement getTooltip(RenderInfo renderInfo);
//     T setTooltip(GuiElement tooltip);
// 
//     /**
//      * Returns the layer this element takes part in.
//      * The standard layer is layer 0. Event handlers will be called for this layer.
//      * @return The layer of this element
//      */
//     int getLayer();
// 
// }


// Path: src/main/java/de/johni0702/minecraft/gui/layout/GridLayout.java
import de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import com.google.common.base.Preconditions;
import de.johni0702.minecraft.gui.container.GuiContainer;
import de.johni0702.minecraft.gui.element.GuiElement;
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
import de.johni0702.minecraft.gui.utils.lwjgl.Point;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;

            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);
    }

    private Pair<int[], int[]> calcNeededCellSize(GuiContainer<?> container) {