From 0b3c68e037c583bf573b24b68a97e56d21ccd17c Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Tue, 4 Aug 2020 20:32:25 +0300 Subject: Make layout() client-only, add missing Environment(CLIENT) annotations to paint() overrides --- .../github/cottonmc/cotton/gui/client/CottonClientScreen.java | 2 ++ .../cottonmc/cotton/gui/client/CottonInventoryScreen.java | 4 ++++ src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java | 3 +++ .../java/io/github/cottonmc/cotton/gui/widget/WButton.java | 1 + .../io/github/cottonmc/cotton/gui/widget/WClippedPanel.java | 3 +++ .../io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java | 3 +++ .../java/io/github/cottonmc/cotton/gui/widget/WLabel.java | 1 + .../java/io/github/cottonmc/cotton/gui/widget/WListPanel.java | 6 +++++- .../java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 2 +- .../java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java | 1 + .../io/github/cottonmc/cotton/gui/widget/WScrollPanel.java | 11 ++++++++--- .../java/io/github/cottonmc/cotton/gui/widget/WTextField.java | 3 ++- 12 files changed, 34 insertions(+), 6 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java index 6adf34e..84e4f1d 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -87,6 +87,8 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree root.setSize(screenWidth, screenHeight); } + + root.layout(); } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java index e69755d..d039061 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -120,6 +120,10 @@ public class CottonInventoryScreen extends Handl basePanel.setSize(screenWidth, screenHeight); } } + + if (basePanel != null) { + basePanel.layout(); + } } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java index 261e2f2..eb1d3b5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java @@ -3,6 +3,8 @@ package io.github.cottonmc.cotton.gui.widget; import io.github.cottonmc.cotton.gui.widget.data.Axis; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import java.util.Objects; @@ -72,6 +74,7 @@ public class WBox extends WPanel { add(widget, 18, 18); } + @Environment(EnvType.CLIENT) @Override public void layout() { int dimension = 0; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java index 719f88e..016eceb 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java @@ -73,6 +73,7 @@ public class WButton extends WWidget { return true; } + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { boolean hovered = (mouseX>=0 && mouseY>=0 && mouseX extends WClippedPanel { scrollBar.setMaxValue(data.size()); scrollBar.setParent(this); } - + + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (scrollBar.getValue()!=lastScroll) { @@ -104,6 +107,7 @@ public class WListPanel extends WClippedPanel { return child; } + @Environment(EnvType.CLIENT) @Override public void layout() { 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 10725ee..b204945 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 @@ -75,6 +75,7 @@ public abstract class WPanel extends WWidget { /** * Uses this Panel's layout rules to reposition and resize components to fit nicely in the panel. */ + @Environment(EnvType.CLIENT) public void layout() { for(WWidget child : children) { if (child instanceof WPanel) ((WPanel) child).layout(); @@ -185,7 +186,6 @@ public abstract class WPanel extends WWidget { @Override public void validate(GuiDescription c) { super.validate(c); - layout(); for (WWidget child : children) { child.validate(c); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index 3ed7e2d..233a90a 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -32,6 +32,7 @@ public class WScrollBar extends WWidget { this.axis = axis; } + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (LibGuiClient.config.darkMode) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java index b4addcc..e4db5a6 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.util.TriState; import net.minecraft.client.util.math.MatrixStack; @@ -29,6 +31,7 @@ public class WScrollPanel extends WClippedPanel { private int lastHorizontalScroll = -1; private int lastVerticalScroll = -1; + private boolean needsLayout = false; /** * Creates a vertically scrolling panel. @@ -60,7 +63,7 @@ public class WScrollPanel extends WClippedPanel { public WScrollPanel setScrollingHorizontally(TriState scrollingHorizontally) { if (scrollingHorizontally != this.scrollingHorizontally) { this.scrollingHorizontally = scrollingHorizontally; - layout(); + needsLayout = true; } return this; @@ -80,7 +83,7 @@ public class WScrollPanel extends WClippedPanel { public WScrollPanel setScrollingVertically(TriState scrollingVertically) { if (scrollingVertically != this.scrollingVertically) { this.scrollingVertically = scrollingVertically; - layout(); + needsLayout = true; } return this; @@ -88,15 +91,17 @@ public class WScrollPanel extends WClippedPanel { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - if (verticalScrollBar.getValue() != lastVerticalScroll || horizontalScrollBar.getValue() != lastHorizontalScroll) { + if (needsLayout || verticalScrollBar.getValue() != lastVerticalScroll || horizontalScrollBar.getValue() != lastHorizontalScroll) { layout(); lastHorizontalScroll = horizontalScrollBar.getValue(); lastVerticalScroll = verticalScrollBar.getValue(); + needsLayout = false; } super.paint(matrices, x, y, mouseX, mouseY); } + @Environment(EnvType.CLIENT) @Override public void layout() { children.clear(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index 191c609..93ebdcb 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java @@ -513,7 +513,8 @@ public class WTextField extends WWidget { @Override public void onFocusGained() { } - + + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { -- cgit