aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuz <6596629+Juuxel@users.noreply.github.com>2022-08-16 15:44:45 +0300
committerJuuz <6596629+Juuxel@users.noreply.github.com>2022-08-16 15:44:45 +0300
commit85e6c34727aa57d59bcea923e24ccb04c35024c5 (patch)
tree6b6167c17bf078733c9c4d91e003de98996f37a3
parent7122942eead07faec0770fe3f32132b6730d1f69 (diff)
downloadLibGui-85e6c34727aa57d59bcea923e24ccb04c35024c5.tar.gz
LibGui-85e6c34727aa57d59bcea923e24ccb04c35024c5.tar.bz2
LibGui-85e6c34727aa57d59bcea923e24ccb04c35024c5.zip
Make WWidget.setHost apply to children and null-safe
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java5
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java8
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java10
3 files changed, 17 insertions, 6 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 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<D, W extends WWidget> 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);
+ }
}
/**