Renderer/src/main/java/electrosphere/renderer/ui/WidgetUtils.java
2021-10-23 22:45:27 -04:00

113 lines
5.0 KiB
Java

package electrosphere.renderer.ui;
import electrosphere.main.Globals;
import electrosphere.renderer.ui.font.TextBox;
import electrosphere.renderer.ui.layout.LayoutSchemeListScrollable;
import electrosphere.renderer.ui.widgets.ImagePanel;
import electrosphere.renderer.ui.widgets.TextInput;
/**
*
* @author amaterasu
*/
public class WidgetUtils {
public static TextBox createTextBox(int positionX, int positionY, int width, int height, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-width/2, positionY, width, height, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-width/2, windowTop, width, height, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedMinSizeTextBox(int charWidth, int charHeight, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedMinSizeTextBoxFromCharCount(int charWidth, int charHeight, int windowTop, String text, boolean render){
int cols = text.length();
int rows = 1;
TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
rVal.setVisible(true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedEditableTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-(int)(width/2.5), windowTop, width, height, rows, cols, text, render, true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static LayoutSchemeListScrollable createListTEST(){
LayoutSchemeListScrollable rVal = new LayoutSchemeListScrollable(200, 200, 500, 500, true);
rVal.addWidget(createVerticallyAlignedMinSizeTextBoxFromCharCount(25, 25, 0, "TESTESTESTEST", true));
rVal.addWidget(WidgetUtils.createTextBox(100, 100, 500, 500, 3, 10, "TEST", true));
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static Widget createWindowTEST(){
Window rVal = new Window(0, 0, 1920, 1080);
// //panel 1
// ImagePanel imagePanel = new ImagePanel();
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
// imagePanel.setPositionX(100);
// imagePanel.setPositionY(100);
// imagePanel.setVisible(true);
// rVal.addWidget(imagePanel);
// //panel 2
// imagePanel = new ImagePanel();
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.testingTexture));
// imagePanel.setVisible(true);
// rVal.addWidget(imagePanel);
// rVal.setVisible(true);
// //window top
// imagePanel = new ImagePanel();
// imagePanel.setTexture(Globals.assetManager.fetchTexture("Textures/ui/WindowBorder.png"));
// imagePanel.setWidth(100);
// imagePanel.setHeight(50);
// imagePanel.setPositionX(200);
// imagePanel.setPositionY(50);
// imagePanel.setVisible(true);
// rVal.addWidget(imagePanel);
TextInput textInput = new TextInput();
textInput.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\nAAAAAAAAAABBBBBBBBBB\n");
textInput.setPositionX(0);
textInput.setPositionY(0);
textInput.setWidth(500);
textInput.setHeight(500);
textInput.setFontWidth(10);
textInput.setFontHeight(27);
textInput.setVisible(true);
rVal.addWidget(textInput);
// TextInput textInput2 = new TextInput();
// textInput2.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\n");
// textInput2.setPositionX(500);
// textInput2.setPositionY(0);
// textInput2.setWidth(500);
// textInput2.setHeight(500);
// textInput2.setFontWidth(20);
// textInput2.setFontHeight(40);
// textInput2.setVisible(true);
// rVal.addWidget(textInput2);
rVal.setVisible(true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
}