So, I’m setting up my menu in Lemur, I’m trying to get something like this:
(Sorry for lack of drawing)
Title
| Start |
| Settings |
| Quit |
Where Start, Settings, and Quit
are in a box about a little lower than mid-screen, and title
hovers a little higher than mid-screen.
Some pseudo-code:
rootId = new ElementId("mainmenu");
root = new Container(new SpringGridLayout(), rootId);
titleContainer = new Container(new SpringGridLayout(), buttonContainerId);
title = new Label("Title",rootId.child("title"));
buttonContainerId = rootId.child("buttonContainer");
buttonContainer = new Container(new SpringGridLayout(), buttonContainerId);
buttonId = buttonContainerId.child("button");
startButton = new Button("Start",buttonId.);
settingsButton = new Button("Settings",buttonId.);
quitButton = new Button("Quit",buttonId.);
titleContainer.addChild(title);
root.addChild(titleContainer);
buttonContainer.addChild(startButton);
buttonContainer.addChild(settingsButton);
buttonContainer.addChild(quitButton);
root.addChild(buttonContainer);
root.setPreferredSize(cam.getWidth, cam.getHeight,root.getPreferredSize().z); // taking z here to preserve layering
root.setLocalTranslation(0, cam.getHeight);
Here is how it currently looks:
There’s some styling going on behind the scenes, but only setting fonts and backgrounds. I can post relevant style if needed, but I really don’t think it applies here. The buttons have no positioning or sizing set on them (meaning I haven’t setPreferredSize
or setLocalTranslation
), and for the moment are fine being pushed down under.
So far, I’ve tried to set the title containers size and position:
setPreferredSize(cam.getWidth() * .5, cam.getHeight() * .25, getPreferredSize().z);
trans = getLocalTranslation();
trans.x = cam.getWidth() * .5;
trans.y = cam.getHeight() * (1 - .25);
setLocalTranslation(trans);
As well as doing the same on the title label itself, and the only thing that produces any effect is when I set the title label height. The width is effectively ignored (with both setSize and setPreferredSize), and the height behaves weird. When the height is set bigger than the original, the buttons below shrink and the title container has the correct size, but anything smaller is ignored (I think it just stretches to fill the remaining space).
I am about 90% sure this is caused by the layout.
I have tried omitting the layout and only providing the ElementId, but I get a NullPointerException
(it seems that new Container(ElementId)
returns null in the absence of a layout).
I picked SpringGridLayout because I assumed I could position things on a grid (as opposed to BorderLayout), but that really isn’t working. I tried replacing that Container
with a Panel
, only to find that Panel
doesn’t accept an ElementId
, which I kind of need for my styles.
So, long story short, how would do I position and size components manually?
Is this a layout issue, where I’m supposed to pass a grid to SpringGridLayout
(and didn’t)?
Or am I barking up the wrong component?
Any help is greatly appreciated!
Note: I started this post drunk and half asleep and finished it first thing this morning (woke up drunk still), so if this makes no sense at all, I completely understand, and feel free to tell me to retypes things without slurring haha