diff options
author | nea <romangraef@gmail.com> | 2022-10-21 03:01:33 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-10-21 03:01:33 +0200 |
commit | ccee8433f74f83cb5360e5668276d104b35629ac (patch) | |
tree | a7bd4799315a5db28e7eafc22f3bde1dcca1bd39 /GuiTest/src/main | |
parent | 9ddc57b0db03fa7afabf23bb7ee490a5c84af393 (diff) | |
download | LibGui-ccee8433f74f83cb5360e5668276d104b35629ac.tar.gz LibGui-ccee8433f74f83cb5360e5668276d104b35629ac.tar.bz2 LibGui-ccee8433f74f83cb5360e5668276d104b35629ac.zip |
Allow WGridPanel to have gaps between widgets.
Diffstat (limited to 'GuiTest/src/main')
3 files changed, 56 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..105c13b --- /dev/null +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/PaddingTestGui.java @@ -0,0 +1,35 @@ +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; } |