I have a question about laying out a GUI with a large text area in the center.
As per my code, when the text is laid out in the SpringGridLayout without the following row of buttons, it looks nice. When the next row is added, which is a button bar, the bar covers the text. Any ideas of how to improve this?
Maybe a BorderLayout would be better than the SpringGridLayout, since I could add the text to the BorderLayout.South position.
Here is the code:
public class AS_Level01 extends AbstractAppState {
private Node guiNode;
private Main main;
float screenWidth, screenHeight;
@Override
public void initialize(AppStateManager stateManager, Application app) {
main = (Main)app;
guiNode = main.getGuiNode();
screenWidth = (float)main.getScreenWidth();
screenHeight = (float)main.getScreenHeight();
SpringGridLayout lvlWinLayout = new SpringGridLayout(Axis.X, Axis.Y, FillMode.Even, FillMode.None);
Container lvlWindow = new Container(lvlWinLayout);
lvlWindow.setBackground(new QuadBackgroundComponent(ColorRGBA.Blue, 5, 5));
Vector3f winDim = new Vector3f(screenHeight, screenHeight * 0.75f, 0f);
lvlWindow.setPreferredSize(winDim);
lvlWindow.setLocalTranslation(
(main.getScreenWidth() - winDim.x) / 2,
main.getScreenHeight() / 2 + winDim.y / 2,
//main.getScreenHeight() - (main.getScreenHeight() - winDim.y) / 2,
// h - (h/2 - d/2) = h/2 + d/2
10f
);
guiNode.attachChild(lvlWindow);
// ADD LABEL
Label label = new Label("Challenge # 1");
label.setColor(ColorRGBA.Yellow);
label.setTextHAlignment(HAlignment.Center);
label.setFontSize(50);
lvlWinLayout.addChild(0, 0, label);
String objectives = ""
+ "Roses are red, violets are blue. Some poems rhyme and some don't. \n "
+ "And also ... \n"
+ "Roses are red and violets are blue. When it rains, I think of you. Drip, Drip, Drip. \n \n"
+ "Some say the world will end in fire, some say in ice. From what I've tasted of desire, "
+ "I hold with those who favor fire. But if it had to perish twice, I know that for destruction "
+ "ice is also great, and will suffice.\n\n"
+ "Sam I am, I am Sam. Do you like green eggs and ham? "
+ "Do you like them in a box? Do you like them with a fox? \n\n"
+ "You need high points to win the game. Low points will only make you lose miserably. ";
Label lab1 = new Label(objectives);
lab1.setFontSize(16);
lab1.setColor(ColorRGBA.White);
lab1.setTextHAlignment(HAlignment.Center);
lvlWinLayout.addChild(0, 1, lab1);
// BUTTON CONTAINER
// UNCOMMENT THESE LINES TO SEE THE LAYOUT PROBLEM WHEN USING A LARGE TEXT AREA.
// SpringGridLayout btnLayout = new SpringGridLayout(Axis.X, Axis.Y, FillMode.Even, FillMode.None);
// Container btnBar = new Container(btnLayout);
// btnBar.setBackground(new QuadBackgroundComponent(ColorRGBA.Cyan, 5, 5));
// lvlWinLayout.addChild(0, 2, btnBar);
//
// Vector3f btnSize = new Vector3f(50f, 50f, 0f);
// float fontSize = 30;
// Button backBtn = new Button("Back");
// backBtn.setFontSize(fontSize);
// backBtn.setTextHAlignment(HAlignment.Center);
// backBtn.setTextVAlignment(VAlignment.Center);
// backBtn.setPreferredSize(btnSize);
// btnLayout.addChild(0, 0, backBtn);
//
// Panel spacer = new Panel();
// spacer.setPreferredSize(btnSize);
// spacer.setBackground(new QuadBackgroundComponent(ColorRGBA.Cyan, 5, 5));
// btnLayout.addChild(1, 0, spacer);
// btnLayout.addChild(2, 0, spacer);
//
// Button acceptBtn = new Button("Accept");
// acceptBtn.setFontSize(fontSize);
// acceptBtn.setTextHAlignment(HAlignment.Center);
// acceptBtn.setTextVAlignment(VAlignment.Center);
// acceptBtn.setPreferredSize(btnSize);
// btnLayout.addChild(3, 0, acceptBtn);
}
@Override
public void cleanup() {
}
@Override
public void update(float tpf) {
}
}