aboutsummaryrefslogtreecommitdiff
path: root/GuiTest
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <romangraef@gmail.com>2022-10-22 14:51:49 +0200
committerGitHub <noreply@github.com>2022-10-22 15:51:49 +0300
commitd76d6d4c9eebabc734dbd71f2838c782e8226c68 (patch)
tree5f129a8d3dd1bbb8a34af8cf028948e8b4470d69 /GuiTest
parent9ddc57b0db03fa7afabf23bb7ee490a5c84af393 (diff)
downloadLibGui-d76d6d4c9eebabc734dbd71f2838c782e8226c68.tar.gz
LibGui-d76d6d4c9eebabc734dbd71f2838c782e8226c68.tar.bz2
LibGui-d76d6d4c9eebabc734dbd71f2838c782e8226c68.zip
Allow WGridPanel to have gaps between widgets. (#170)
* Allow WGridPanel to have gaps between widgets. * Various formatting changes
Diffstat (limited to 'GuiTest')
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java11
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/client/PaddingTestGui.java34
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java11
3 files changed, 55 insertions, 1 deletions
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java
index 2d6c5b7..ead774b 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java
@@ -1,6 +1,7 @@
package io.github.cottonmc.test.client;
import com.mojang.brigadier.Command;
+import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
@@ -20,6 +21,7 @@ import io.github.cottonmc.test.TestDescription;
import java.util.function.Function;
+import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
public class LibGuiTestClient implements ClientModInitializer {
@@ -46,6 +48,15 @@ public class LibGuiTestClient implements ClientModInitializer {
.then(literal("scrolling").executes(openScreen(client -> new ScrollingTestGui())))
.then(literal("insets").executes(openScreen(client -> new InsetsTestGui())))
.then(literal("textfield").executes(openScreen(client -> new TextFieldTestGui())))
+ .then(literal("paddings")
+ .then(argument("horizontal", IntegerArgumentType.integer(0))
+ .then(argument("vertical", IntegerArgumentType.integer(0))
+ .executes(context -> {
+ var hori = IntegerArgumentType.getInteger(context, "horizontal");
+ var vert = IntegerArgumentType.getInteger(context, "vertical");
+ return openScreen(client -> new PaddingTestGui(hori, vert)).run(context);
+ }))))
+
));
}
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/PaddingTestGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/PaddingTestGui.java
new file mode 100644
index 0000000..367cab0
--- /dev/null
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/PaddingTestGui.java
@@ -0,0 +1,34 @@
+package io.github.cottonmc.test.client;
+
+import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
+import io.github.cottonmc.cotton.gui.widget.WGridPanel;
+import io.github.cottonmc.cotton.gui.widget.WLabel;
+import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
+import io.github.cottonmc.cotton.gui.widget.data.Insets;
+import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment;
+
+import net.minecraft.text.Text;
+
+public class PaddingTestGui extends LightweightGuiDescription {
+ public PaddingTestGui(int hori, int vert) {
+ var root = new WGridPanel();
+ root.setGaps(hori, vert);
+ setRootPanel(root);
+ root.setInsets(Insets.ROOT_PANEL);
+
+ addBox(root, 0, 0, 2, 1);
+ addBox(root, 0, 1, 1, 2);
+ addBox(root, 1, 1, 1, 1);
+ addBox(root, 1, 2, 1, 1);
+
+ root.validate(this);
+ }
+
+ void addBox(WGridPanel root, int x, int y, int w, int h) {
+ root.add(new TestClientGui.WColorBox(0xffff0000), x, y, w, h);
+ var l = new WLabel(Text.literal(w + "x" + h), 0xff00ffff);
+ l.setVerticalAlignment(VerticalAlignment.CENTER);
+ l.setHorizontalAlignment(HorizontalAlignment.CENTER);
+ root.add(l, x, y, w, h);
+ }
+}
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
index 672e56d..839072e 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
@@ -134,7 +134,16 @@ public class TestClientGui extends LightweightGuiDescription {
public static class WColorBox extends WWidget {
protected int color = 0xFF_FFFFFF;
public WColorBox() {}
-
+
+ public WColorBox(int col) {
+ this.color = col;
+ }
+
+ @Override
+ public boolean canResize() {
+ return true;
+ }
+
public void setColor(int col) {
this.color = col;
}