From e9523d714508e15ae0262a21cccec847250e2bcd Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Tue, 2 Feb 2021 17:52:04 +0200 Subject: Add test gui for scroll panels --- .../cottonmc/test/client/ScrollingTestGui.java | 24 ++++++++++++++++++++++ .../github/cottonmc/test/client/TestClientGui.java | 10 +++++++++ 2 files changed, 34 insertions(+) create mode 100644 GuiTest/src/main/java/io/github/cottonmc/test/client/ScrollingTestGui.java diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/ScrollingTestGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/ScrollingTestGui.java new file mode 100644 index 0000000..3dc41d3 --- /dev/null +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/ScrollingTestGui.java @@ -0,0 +1,24 @@ +package io.github.cottonmc.test.client; + +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; +import io.github.cottonmc.cotton.gui.widget.WBox; +import io.github.cottonmc.cotton.gui.widget.WButton; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import io.github.cottonmc.cotton.gui.widget.WScrollPanel; +import io.github.cottonmc.cotton.gui.widget.data.Axis; + +import net.minecraft.text.LiteralText; + +public class ScrollingTestGui extends LightweightGuiDescription { + public ScrollingTestGui() { + WGridPanel root = (WGridPanel) rootPanel; + WBox box = new WBox(Axis.VERTICAL); + + for (int i = 0; i < 20; i++) { + box.add(new WButton(new LiteralText("Button #" + i))); + } + + root.add(new WScrollPanel(box), 0, 0, 5, 3); + root.validate(this); + } +} 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 bdc47b3..de5df3d 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 @@ -1,7 +1,11 @@ package io.github.cottonmc.test.client; +import io.github.cottonmc.cotton.gui.client.CottonClientScreen; +import io.github.cottonmc.cotton.gui.widget.WButton; + import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.LiteralText; import net.minecraft.util.Identifier; @@ -107,6 +111,12 @@ public class TestClientGui extends LightweightGuiDescription { this.b = i; updateCol(col); }); + + WButton openOther = new WButton(new LiteralText("Go to scrolling")); + openOther.setOnClick(() -> { + MinecraftClient.getInstance().openScreen(new CottonClientScreen(new ScrollingTestGui())); + }); + root.add(openOther, 0, -1, 4, 1); root.validate(this); -- cgit