Skip to content

Commit

Permalink
added centered boolean to TextWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Dec 10, 2023
1 parent 2a16b64 commit 43778a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
public class SyncableTextWidget extends TextWidget {
String text = "";
final Function<IGuiHandler, String> syncFunction;
protected SyncableTextWidget(@NotNull GuiInstance gui, @Nullable IGuiElement parent, int color, Function<IGuiHandler, String> syncFunction) {
super(gui, parent, a-> ((SyncableTextWidget)a).text, color);
protected SyncableTextWidget(@NotNull GuiInstance gui, @Nullable IGuiElement parent, Function<IGuiHandler, String> syncFunction, int color, boolean centered){
super(gui, parent, a-> ((SyncableTextWidget)a).text, color, centered);
this.syncFunction = syncFunction;

}

public static WidgetSupplier build(Function<IGuiHandler, String> textSyncFunction, int color) {
return builder((a, b) -> new SyncableTextWidget(a, b, color, textSyncFunction));
public static WidgetSupplier build(Function<IGuiHandler, String> textSyncFunction, int color, boolean centered) {
return builder((a, b) -> new SyncableTextWidget(a, b, textSyncFunction, color, centered));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ public class TextWidget extends Widget {
private final Function<TextWidget, String> getter;
private final int color;

protected TextWidget(GuiInstance gui, IGuiElement parent, String text, int color) {
super(gui, parent);
this.getter = a -> text;
this.color = color;
private final boolean centered;

protected TextWidget(GuiInstance gui, IGuiElement parent, String text, int color, boolean centered) {
this(gui, parent, a -> text, color, centered);
}

protected TextWidget(GuiInstance gui, IGuiElement parent, Function<TextWidget, String> getter, int color) {
protected TextWidget(GuiInstance gui, IGuiElement parent, Function<TextWidget, String> getter, int color, boolean centered) {
super(gui, parent);
this.getter = getter;
this.color = color;
this.centered = centered;
}

public static WidgetSupplier build(String text, int color) {
return builder((a, b) -> new TextWidget(a, b, text, color)).clientSide();
public static WidgetSupplier build(String text, int color, boolean centered) {
return builder((a, b) -> new TextWidget(a, b, text, color, centered)).clientSide();
}

@Override
Expand All @@ -37,6 +38,6 @@ public void render(PoseStack matrixStack, double mouseX, double mouseY, float pa
int xScaled = textWidth / 2;
int xCenter = (getW() / 2);
int xPosition = xCenter - xScaled;
this.drawText(matrixStack, Utils.literal(text), realX() + xPosition, realY(), color);
this.drawText(matrixStack, Utils.literal(text), (centered ? realX() + xPosition : realX()), realY(), color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BasicMachine(String domain, String id) {
protected void setupGui() {
super.setupGui();
addGuiCallback(t -> {
t.addWidget(WidgetSupplier.build((a, b) -> TextWidget.build(((AntimatterContainerScreen<?>) b).getTitle().getString(), 4210752).build(a, b)).setPos(9, 5).clientSide());
t.addWidget(WidgetSupplier.build((a, b) -> TextWidget.build(((AntimatterContainerScreen<?>) b).getTitle().getString(), 4210752, false).build(a, b)).setPos(9, 5).clientSide());
if (has(RECIPE)) {
t.addWidget(ProgressWidget.build())
.addWidget(MachineStateWidget.build());
Expand Down

0 comments on commit 43778a0

Please sign in to comment.