aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-01-26 13:02:28 +0200
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-01-26 13:02:28 +0200
commit0db57038b6aa6622ff4078e4c3c33dbc6f98c4b4 (patch)
treea8578f4690107ae4d4c4110a78db6934cafa81f5
parentbdb2f5e734c3afe352830b74a8ab34102a4336a6 (diff)
downloadLibGui-0db57038b6aa6622ff4078e4c3c33dbc6f98c4b4.tar.gz
LibGui-0db57038b6aa6622ff4078e4c3c33dbc6f98c4b4.tar.bz2
LibGui-0db57038b6aa6622ff4078e4c3c33dbc6f98c4b4.zip
Fix list panels not always setting their children's host
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java18
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java3
2 files changed, 17 insertions, 4 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 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);
}