[Lemur] How to center panels?

So, in the Lemur Getting Started page, it says to Put it somewhere that we will see it. by using:
myWindow.setLocalTranslation(300, 300, 0);

But this places it in different positions depending on the resolution, i.e. the middle of a theoretical 600x600 display, but only in the top left corner of a theoretical 1200x1200 display. Those numbers are obviously bogus, but I feel they demonstrate what I’m getting at.

So my question is, setting things like adjusting the “center” of a panel for inset/margin aside, how would one modify this example to center the panel to the middle of the screen?

Or, more simply, would any of the solutions mentioned here to get screen size be applicable to this? Such as get screenSize/2 for screenCenter?

I feel this is a very prominent use case, as in my experience with HTML, hardcoding dimensions leads to massive breakage on different resolutions, and I definitely feel that, if available, centering panels like this would be used much for often than absolute positioning.

If I have missed something somewhere, please correct me

You can obtain the display size from the default Camera, using

        float width = cam.getWidth();
        float height = cam.getHeight();
1 Like

The example was meant to be as straight forward as possible.

Centering is reasonably staight-forward… just more than I wanted to put in a simple example.

Manually:

Vector3f pref = panel.getPreferredSize().mult(0.5f);
panel.setLocalTranslation(camera.getWidth() * 0.5f - pref.x, camera.getHeight() * 0.5f + pref.y, 0);

The unreleased 1.15 has some convenience functions for this on the PopupState. These are more full-featured in that they will deal with differently scaled GUIs.

…because it is also often the case that GUIs may pick a single set of resolutions and then scale to them.

2 Likes

Much appreciated!

1 Like

Gotcha, Much appreciated!

1 Like