From 0db57038b6aa6622ff4078e4c3c33dbc6f98c4b4 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sun, 26 Jan 2020 13:02:28 +0200
Subject: Fix list panels not always setting their children's host

---
 .../github/cottonmc/cotton/gui/widget/WListPanel.java  | 18 ++++++++++++++----
 .../io/github/cottonmc/cotton/gui/widget/WPanel.java   |  3 +++
 2 files changed, 17 insertions(+), 4 deletions(-)

(limited to 'src/main/java/io')

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 fe2cc1b..0c002da 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
@@ -6,7 +6,6 @@ import java.util.List;
 import java.util.function.BiConsumer;
 import java.util.function.Supplier;
 
-import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
 import io.github.cottonmc.cotton.gui.widget.data.Axis;
 
 /**
@@ -67,7 +66,18 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel {
 			child.paintBackground(x + child.getX(), y + child.getY(), mouseX - child.getX(), mouseY - child.getY());
 		}*/
 	}
-	
+
+	private W createChild() {
+		W child = supplier.get();
+		child.setParent(this);
+		// Set up the widget's host
+		if (host != null) {
+			child.validate(host);
+			child.createPeers(host);
+		}
+		return child;
+	}
+
 	@Override
 	public void layout() {
 		
@@ -86,7 +96,7 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel {
 		if (!fixedHeight) {
 			if (unconfigured.isEmpty()) {
 				if (configured.isEmpty()) {
-					W exemplar = supplier.get();
+					W exemplar = createChild();
 					unconfigured.add(exemplar);
 					if (!exemplar.canResize()) cellHeight = exemplar.getHeight();
 				} else {
@@ -128,7 +138,7 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel {
 				W w = configured.get(d);
 				if (w==null) {
 					if (unconfigured.isEmpty()) {
-						w = supplier.get();
+						w = createChild();
 					} else {
 						w = unconfigured.remove(0);
 					}
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 33ca28c..7e227f7 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
@@ -140,6 +140,9 @@ public abstract class WPanel extends WWidget {
 	@Override
 	public void validate(GuiDescription c) {
 		layout();
+		for (WWidget child : children) {
+			child.validate(c);
+		}
 		if (c!=null) createPeers(c);
 	}
 	
-- 
cgit