I’ve been experimenting with Lemur and it seems very good so far, however I’m running into one thing that’s stumped me.
I’m trying to create a window centered on the screen, so to do that I thought I’d create a Container filling the screen with the BorderLayout and then add the popup as a Container inside that.
However when I try it the window just appears in the upper left corner. I’ve tried using both SpringGridLayout and BorderLayout for the outer Container and I’;ve also tried calling setSize on it.
(I’ve scaled the GUI node so it is always 1280x720)
final Container guiWrapper = new Container();
guiWrapper.setLocalTranslation(0, 720, 0);
guiWrapper.setSize(new Vector3f(1280, 720, 1));
guiNode.attachChild(guiWrapper);
SpringGridLayout layout = new SpringGridLayout(Axis.X, Axis.Y, FillMode.Proportional, FillMode.Proportional);
guiWrapper.setLayout(layout);
final Container introWindow = new Container();
guiWrapper.addChild(introWindow);
introWindow.addChild(new Label("Gem Gnolls attack!"));
Button clickMe = introWindow.addChild(new Button("Defend Yourself!"));
clickMe.addClickCommands(new Command<Button>() {
@Override
public void execute( Button source ) {
guiWrapper.detachChild(introWindow);
}
});
Is there something I’m missing here?
If I just want a popup style window centered on the screen how do I do that in Lemur?
setSize() is not what you want… setPreferredSize() is.
setSize() is what the layouts call to set the size and it’s what the GUI control itself will call the first time a root-level window is displayed… based on the preferred size.
Thanks @pspeed, I called setPreferredSize and it worked perfectly. It’s a shame setSize is public really (I assume it needs to be?) since it’s easy to cause confusion that way.
For now I’m just messing around trying a few concepts out, but that modal popup does look perfect for when I properly implement this in the future. Thanks.
Yes, it needs to be… and you can call it after you have your GUI attached and rendered and it will work as expected. (useful for animation)
It’s just that when a root GUI element is first displayed it will auto size itself. (And laid out components will of course have their setSize() called whenever the layout happens.)