From 5f108ee93b32475d254f82032b7919986a7b0706 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Tue, 30 Jun 2020 20:14:24 +0300 Subject: Add WWidget.host accessors, use them in WListPanel to avoid unsafe validations --- .../cottonmc/cotton/gui/widget/WListPanel.java | 5 +++-- .../github/cottonmc/cotton/gui/widget/WWidget.java | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src') 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 9ba8562..bcfbf2b 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 @@ -97,8 +97,9 @@ public class WListPanel extends WClippedPanel { child.setParent(this); // Set up the widget's host if (host != null) { - child.validate(host); - child.createPeers(host); + // setHost instead of validate since we cannot have independent validations + // TODO: System for independently validating widgets? + child.setHost(host); } return child; } 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 8df8e14..824a5b2 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 @@ -367,6 +367,29 @@ public class WWidget { this.host = host; } + /** + * Gets the host of this widget. + * + * @return the host + * @see #host + * @since 2.1.0 + */ + @Nullable + public final GuiDescription getHost() { + return host; + } + + /** + * Sets the host of this widget without creating peers. + * + * @param host the new host + * @see #host + * @since 2.1.0 + */ + public void setHost(@Nullable GuiDescription host) { + this.host = host; + } + /** * Adds lines to this widget's tooltip. If the lines remain empty after this call, no tooltip will be drawn. * @param tooltip List containing all previous tooltip data. -- cgit