From 72b670a3b4f682fc131eb58d4c39d38330bbd6f7 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Sun, 11 Jun 2023 13:44:58 +0300 Subject: Fix incorrect title positions for non-left alignments --- .../cottonmc/test/client/LibGuiTestClient.java | 8 ++++- .../test/client/TitleAlignmentTestGui.java | 35 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/testMod/java/io/github/cottonmc/test/client/TitleAlignmentTestGui.java (limited to 'src/testMod/java/io') 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 openScreen(Function screenFactory) { + return openScreen(ScreenTexts.EMPTY, screenFactory); + } + + private static Command openScreen(Text title, Function 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; + } +} -- cgit