diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-08-04 20:32:25 +0300 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-08-04 20:32:25 +0300 |
commit | 0b3c68e037c583bf573b24b68a97e56d21ccd17c (patch) | |
tree | 8a5142c72a4347564f1ec42e4fedb1e2a0ecb457 /src/main | |
parent | a4bb001575a802acebdbbeecb323e1949f8cdffe (diff) | |
download | LibGui-0b3c68e037c583bf573b24b68a97e56d21ccd17c.tar.gz LibGui-0b3c68e037c583bf573b24b68a97e56d21ccd17c.tar.bz2 LibGui-0b3c68e037c583bf573b24b68a97e56d21ccd17c.zip |
Make layout() client-only, add missing Environment(CLIENT) annotations to paint() overrides
Diffstat (limited to 'src/main')
12 files changed, 34 insertions, 6 deletions
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<T extends SyncedGuiDescription> 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<getWidth() && mouseY<getHeight()); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java index 531ae85..9a93c7a 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java @@ -1,12 +1,15 @@ package io.github.cottonmc.cotton.gui.widget; import io.github.cottonmc.cotton.gui.client.Scissors; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; /** * A panel that is clipped to only render widgets inside its bounds. */ public class WClippedPanel extends WPanel { + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (getBackgroundPainter()!=null) getBackgroundPainter().paintBackground(x, y, this); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java index a3adac9..0412b83 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; import io.github.cottonmc.cotton.gui.client.LibGuiClient; @@ -34,6 +36,7 @@ public class WDynamicLabel extends WWidget { this(text, DEFAULT_TEXT_COLOR); } + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { String tr = text.get(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java index fddc09a..7cc76e9 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java @@ -79,6 +79,7 @@ public class WLabel extends WWidget { this(text, DEFAULT_TEXT_COLOR); } + @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { MinecraftClient mc = MinecraftClient.getInstance(); 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 bcfbf2b..9bef3e0 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 @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; import io.github.cottonmc.cotton.gui.widget.data.Axis; @@ -69,7 +71,8 @@ public class WListPanel<D, W extends WWidget> 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<D, W extends WWidget> 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) { |