diff options
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index 5440bd5..39a7a26 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java @@ -4,8 +4,10 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; +import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.widget.data.Axis; import io.github.cottonmc.cotton.gui.widget.data.InputResult; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -59,6 +61,11 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { private int lastScroll = -1; /** + * The widgets whose host hasn't been set yet. + */ + private final List<W> requiresHost = new ArrayList<>(); + + /** * Constructs a list panel. * * @param data the list data @@ -104,11 +111,32 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { // setHost instead of validate since we cannot have independent validations // TODO: System for independently validating widgets? child.setHost(host); + } else { + requiresHost.add(child); } return child; } @Override + public void validate(GuiDescription c) { + super.validate(c); + setRequiredHosts(c); + } + + @Override + public void setHost(@Nullable GuiDescription host) { + super.setHost(host); + if (host != null) setRequiredHosts(host); + } + + private void setRequiredHosts(GuiDescription host) { + for (W widget : requiresHost) { + widget.setHost(host); + } + requiresHost.clear(); + } + + @Override public void layout() { this.children.clear(); |