diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2022-08-16 15:42:25 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2022-08-16 15:42:25 +0300 |
commit | 7122942eead07faec0770fe3f32132b6730d1f69 (patch) | |
tree | 814fa581815963d2b689cd1657bc39bb4368f802 /src | |
parent | c0f26cab080c130b11693ea707220a4d20a735fc (diff) | |
download | LibGui-7122942eead07faec0770fe3f32132b6730d1f69.tar.gz LibGui-7122942eead07faec0770fe3f32132b6730d1f69.tar.bz2 LibGui-7122942eead07faec0770fe3f32132b6730d1f69.zip |
Fix #169
Diffstat (limited to 'src')
-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(); |