package fr.altarik.toolbox.core.client.gui;

import net.minecraft.client.gui.widget.Positioner;
import net.minecraft.client.gui.widget.SimplePositioningWidget;
import net.minecraft.client.gui.widget.Widget;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public abstract class ExtendedSimplePositionWidget extends SimplePositioningWidget {

    private final List<Element> elements = new ArrayList<>();

    public ExtendedSimplePositionWidget(int x, int y, int width, int height) {
        super(x, y, width, height);
    }

    @Override
    public <T extends Widget> T add(T widget, Positioner positioner) {
        this.elements.add(new Element(widget, positioner));
        return widget;
    }

    public <T extends Widget> void remove(T widget) {
        this.elements.remove(new Element(widget, this.copyPositioner()));
    }

    @Override
    public void forEachElement(Consumer<Widget> consumer) {
        this.elements.forEach((element) -> consumer.accept(element.widget));
    }

}
