diff options
Diffstat (limited to 'src')
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 310b9aa..877528c 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 @@ -138,7 +138,7 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { if (getTitle() != null && description.isTitleVisible()) { int width = description.getRootPanel().getWidth(); - ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - titleX, description.getTitleColor()); + ScreenDrawing.drawString(context, 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 04025a6..b1ed4ce 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 @@ -313,7 +313,7 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl protected void drawForeground(DrawContext context, int mouseX, int mouseY) { if (description != null && description.isTitleVisible()) { int width = description.getRootPanel().getWidth(); - ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), titleX, titleY, width - titleX, description.getTitleColor()); + ScreenDrawing.drawString(context, 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; + } +} |