aboutsummaryrefslogtreecommitdiff
path: root/src/testMod
diff options
context:
space:
mode:
authorJuuz <6596629+Juuxel@users.noreply.github.com>2023-06-11 13:44:58 +0300
committerJuuz <6596629+Juuxel@users.noreply.github.com>2023-06-11 13:44:58 +0300
commit72b670a3b4f682fc131eb58d4c39d38330bbd6f7 (patch)
treed368444b697e057fd1fdf9ceaa962f255b6b217c /src/testMod
parent8eb600e9c6e3e722f243fc540c887309ce4c9d1c (diff)
downloadLibGui-72b670a3b4f682fc131eb58d4c39d38330bbd6f7.tar.gz
LibGui-72b670a3b4f682fc131eb58d4c39d38330bbd6f7.tar.bz2
LibGui-72b670a3b4f682fc131eb58d4c39d38330bbd6f7.zip
Fix incorrect title positions for non-left alignments
Diffstat (limited to 'src/testMod')
-rw-r--r--src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java8
-rw-r--r--src/testMod/java/io/github/cottonmc/test/client/TitleAlignmentTestGui.java35
2 files changed, 42 insertions, 1 deletions
diff --git a/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java b/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java
index a8121fb..e15eb83 100644
--- a/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java
+++ b/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java
@@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallba
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
+import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
@@ -65,13 +66,18 @@ public class LibGuiTestClient implements ClientModInitializer {
.then(literal("#182").executes(openScreen(client -> new Issue182TestGui())))
.then(literal("#196").executes(openScreen(client -> new Issue196TestGui())))
.then(literal("darkmode").executes(openScreen(client -> new DarkModeTestGui())))
+ .then(literal("titlealignment").executes(openScreen(Text.literal("test title"), client -> new TitleAlignmentTestGui())))
));
}
private static Command<FabricClientCommandSource> openScreen(Function<MinecraftClient, LightweightGuiDescription> screenFactory) {
+ return openScreen(ScreenTexts.EMPTY, screenFactory);
+ }
+
+ private static Command<FabricClientCommandSource> openScreen(Text title, Function<MinecraftClient, LightweightGuiDescription> screenFactory) {
return context -> {
var client = context.getSource().getClient();
- client.send(() -> client.setScreen(new CottonClientScreen(screenFactory.apply(client))));
+ client.send(() -> client.setScreen(new CottonClientScreen(title, screenFactory.apply(client))));
return Command.SINGLE_SUCCESS;
};
}
diff --git a/src/testMod/java/io/github/cottonmc/test/client/TitleAlignmentTestGui.java b/src/testMod/java/io/github/cottonmc/test/client/TitleAlignmentTestGui.java
new file mode 100644
index 0000000..46b3185
--- /dev/null
+++ b/src/testMod/java/io/github/cottonmc/test/client/TitleAlignmentTestGui.java
@@ -0,0 +1,35 @@
+package io.github.cottonmc.test.client;
+
+import net.minecraft.text.Text;
+
+import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
+import io.github.cottonmc.cotton.gui.widget.WGridPanel;
+import io.github.cottonmc.cotton.gui.widget.WLabeledSlider;
+import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
+
+public class TitleAlignmentTestGui extends LightweightGuiDescription {
+ private static final HorizontalAlignment[] TITLE_ALIGNMENTS = {
+ HorizontalAlignment.LEFT,
+ HorizontalAlignment.CENTER,
+ HorizontalAlignment.RIGHT
+ };
+ private HorizontalAlignment titleAlignment = HorizontalAlignment.LEFT;
+
+ public TitleAlignmentTestGui() {
+ WLabeledSlider titleSlider = new WLabeledSlider(0, TITLE_ALIGNMENTS.length - 1);
+ titleSlider.setLabel(getLabel(HorizontalAlignment.LEFT));
+ titleSlider.setLabelUpdater(value -> getLabel(TITLE_ALIGNMENTS[value]));
+ titleSlider.setValueChangeListener(value -> titleAlignment = TITLE_ALIGNMENTS[value]);
+ ((WGridPanel) rootPanel).add(titleSlider, 0, 1, 4, 1);
+ rootPanel.validate(this);
+ }
+
+ private Text getLabel(HorizontalAlignment alignment) {
+ return Text.literal(alignment.name());
+ }
+
+ @Override
+ public HorizontalAlignment getTitleAlignment() {
+ return titleAlignment;
+ }
+}