Skip to content

Commit

Permalink
Make WWidget.setHost apply to children and null-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Aug 16, 2022
1 parent 7122942 commit 85e6c34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
Expand Down Expand Up @@ -124,9 +123,9 @@ public void validate(GuiDescription c) {
}

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public void validate(GuiDescription c) {
}
}

@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) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,18 @@ public final GuiDescription getHost() {
}

/**
* 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);
}
}

/**
Expand Down

0 comments on commit 85e6c34

Please sign in to comment.