From 85e6c34727aa57d59bcea923e24ccb04c35024c5 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Tue, 16 Aug 2022 15:44:45 +0300 Subject: Make WWidget.setHost apply to children and null-safe --- .../java/io/github/cottonmc/cotton/gui/widget/WListPanel.java | 5 ++--- src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 8 ++++++++ .../java/io/github/cottonmc/cotton/gui/widget/WWidget.java | 10 +++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src/main/java') 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 39a7a26..9cd83fd 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 @@ -7,7 +7,6 @@ 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; @@ -124,9 +123,9 @@ public class WListPanel extends WClippedPanel { } @Override - public void setHost(@Nullable GuiDescription host) { + public void setHost(GuiDescription host) { super.setHost(host); - if (host != null) setRequiredHosts(host); + setRequiredHosts(host); } private void setRequiredHosts(GuiDescription host) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index d91950e..b6d0169 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java @@ -130,6 +130,14 @@ public abstract class WPanel extends WWidget { } } + @Override + public void setHost(GuiDescription host) { + super.setHost(host); + for (WWidget child : children) { + child.setHost(host); + } + } + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index 9636e8b..eb69e50 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -386,14 +386,18 @@ public class WWidget { } /** - * Sets the host of this widget without creating peers. + * Sets the host of this widget and all its children without creating peers. * * @param host the new host * @see #host * @since 2.1.0 */ - public void setHost(@Nullable GuiDescription host) { - this.host = host; + public void setHost(GuiDescription host) { + if (host != null) { + this.host = host; + } else { + LOGGER.warn("Setting null host for {}", this); + } } /** -- cgit