@@ -9,26 +9,31 @@ public class Text extends Gidget implements TextHolder {
99 private final Font font ;
1010 private final Component text ;
1111 private final int color ;
12- private final boolean centered ;
12+ private final Positioned positioned ;
1313 private final boolean shadow ;
1414
15- public Text (Font font , Component text , int x , int y , int color , boolean centered , boolean shadow ) {
15+ public Text (Font font , Component text , int x , int y , int color , Positioned positioned , boolean shadow ) {
1616 super (x , y , font .width (text .getString ()), font .lineHeight );
1717 this .font = font ;
1818 this .text = text ;
1919 this .color = color ;
20- this .centered = centered ;
20+ this .positioned = positioned ;
2121 this .shadow = shadow ;
2222 }
2323
2424 @ Override
2525 public void render (GuiGraphics guiGraphics , int mouseX , int mouseY ) {
26- int finalX = this .x ;
27- if (this .centered ) {
28- finalX -= this .width / 2 ;
26+ int finalX = this .x () ;
27+ if (this .positioned == Positioned . BOTH || this . positioned == Positioned . CENTER_HORIZONTAL ) {
28+ finalX -= this .width () / 2 ;
2929 }
3030
31- guiGraphics .drawString (this .font , this .text , finalX , this .y , this .color , this .shadow );
31+ int finalY = this .y ();
32+ if (this .positioned == Positioned .BOTH || this .positioned == Positioned .CENTER_VERTICAL ) {
33+ finalY -= this .height () / 2 ;
34+ }
35+
36+ guiGraphics .drawString (this .font , this .text , finalX , finalY , this .color , this .shadow );
3237 }
3338
3439 @ Override
@@ -40,8 +45,8 @@ public int getColor() {
4045 return this .color ;
4146 }
4247
43- public boolean isCentered () {
44- return this .centered ;
48+ public Positioned getPositioned () {
49+ return this .positioned ;
4550 }
4651
4752 public boolean hasShadow () {
@@ -54,7 +59,7 @@ public static class Builder {
5459 private final int y ;
5560
5661 private int color = ARGB .white (1.0F );
57- private boolean centered = false ;
62+ private Positioned positioned = Positioned . NONE ;
5863 private boolean shadow = true ;
5964
6065 public Builder (Component text , int x , int y ) {
@@ -77,13 +82,25 @@ public Builder withShadow(boolean shadow) {
7782 return this ;
7883 }
7984
85+ public Builder positioned (Positioned positioned ) {
86+ this .positioned = positioned ;
87+ return this ;
88+ }
89+
8090 public Builder centered () {
81- this .centered = true ;
91+ this .positioned = Positioned . CENTER_HORIZONTAL ;
8292 return this ;
8393 }
8494
8595 public Text build (Font font ) {
86- return new Text (font , this .text , this .x , this .y , this .color , this .centered , this .shadow );
96+ return new Text (font , this .text , this .x , this .y , this .color , this .positioned , this .shadow );
8797 }
8898 }
99+
100+ public enum Positioned {
101+ CENTER_VERTICAL ,
102+ CENTER_HORIZONTAL ,
103+ BOTH ,
104+ NONE
105+ }
89106}
0 commit comments