Adds the setText function to the Button class.
@@ -2,6 +2,7 @@ package com.valkryst.VTerminal.component;
import com.valkryst.VTerminal.Tile;
import com.valkryst.VTerminal.Screen;
+import com.valkryst.VTerminal.TileGrid;
import com.valkryst.VTerminal.builder.ButtonBuilder;
import com.valkryst.VTerminal.palette.ColorPalette;
import lombok.Getter;
@@ -207,4 +208,30 @@ public class Button extends Component {
tile.setForegroundColor(foregroundColor);
}
}
+
+ /**
+ * Sets the text displayed on the button.
+ *
+ * @param text
+ * The new text.
+ */
+ public void setText(String text) {
+ if (text == null) {
+ text = "";
+ }
+
+ for (int x = 0 ; x < tiles.getWidth() ; x++) {
+ if (x == 0 || x == 1) {
+ continue;
+ }
+
+ if (x <= text.length()) {
+ // Because we skip the first two tiles (checkbox & space after it), we have to use -2 to
+ // compensate.
+ tiles.getTileAt(x, 0).setCharacter(text.charAt(x - 2));
+ } else {
+ tiles.getTileAt(x, 0).setCharacter(' ');
+ }
+ }
+ }
}
\ No newline at end of file
