aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java2
-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
4 files changed, 44 insertions, 3 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index 81d7646..0df0597 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -139,7 +139,7 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl {
if (getTitle() != null && description.isTitleVisible()) {
int width = description.getRootPanel().getWidth();
- ScreenDrawing.drawString(matrices, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - titleX, description.getTitleColor());
+ ScreenDrawing.drawString(matrices, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - 2 * titleX, description.getTitleColor());
}
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index 61fc287..013856d 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -314,7 +314,7 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl
protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) {
if (description != null && description.isTitleVisible()) {
int width = description.getRootPanel().getWidth();
- ScreenDrawing.drawString(matrices, getTitle().asOrderedText(), description.getTitleAlignment(), titleX, titleY, width - titleX, description.getTitleColor());
+ ScreenDrawing.drawString(matrices, getTitle().asOrderedText(), description.getTitleAlignment(), titleX, titleY, width - 2 * titleX, description.getTitleColor());
}
// Don't draw the player inventory label as it's drawn by the widget itself
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;
+ }
+}