Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: A handy method in GuiGlobals to position Panel #79

Open
Ali-RS opened this issue Apr 7, 2019 · 2 comments
Open

Proposal: A handy method in GuiGlobals to position Panel #79

Ali-RS opened this issue Apr 7, 2019 · 2 comments

Comments

@Ali-RS
Copy link
Contributor

Ali-RS commented Apr 7, 2019

I have a GuiManager with a static method to position a Panel on gui (ex: Center, Left, Right, Up, Bottom)

GuiManager.setPosition(panel, GuiManager.Position.CENTER, getApplication().getCamera());

public static void setPosition(Panel panel, Position position, Camera cam) {
       // Apply standard scale
       float scale = getStandardScale(cam);
       panel.setLocalScale(1.2f * scale);

       int width = cam.getWidth();
       int height = cam.getHeight();

       Vector3f prefSize = new Vector3f(panel.getPreferredSize());
       prefSize.multLocal(1.2f * scale);
       // Position window to selected gui pos
       switch (position) {
           case CENTER:
               panel.setLocalTranslation((width - prefSize.x) / 2, (height + prefSize.y) / 2, 0);
               break;
           case RIGHT:
               panel.setLocalTranslation((width - prefSize.x), (height + prefSize.y) / 2, 0);
               break;
           case LEFT:
               panel.setLocalTranslation(0, (height + prefSize.y) / 2, 0);
               break;
           case TOP:
               panel.setLocalTranslation((width - prefSize.x) / 2, height, 0);
               break;
           case BOTTOM:
               panel.setLocalTranslation((width - prefSize.x) / 2, prefSize.y, 0);
               break;
       }
   }

Would be something similar useful to add in GuiGlobals ?

@Ali-RS Ali-RS changed the title Feature Request: Add a handy method in GuiGlobals to position Panel Proposal: Add a handy method in GuiGlobals to position Panel Apr 7, 2019
@Ali-RS Ali-RS changed the title Proposal: Add a handy method in GuiGlobals to position Panel Proposal: A handy method in GuiGlobals to position Panel Apr 7, 2019
@pspeed42
Copy link
Contributor

pspeed42 commented Apr 7, 2019

I don't think it belongs on GuiGlobals as it isn't really what it's for and also "which camera" becomes a critial question centrally. On something lilke PopupState it probably makes sense because that both is already tied to one camera/root and has a concept of a scaling that is different than Camera by itself. (Useful for resolution independent UIs.)

Wherever the method goes, it doesn't need its own position enum, though. It can just combine HAlignment and VAlignment... which would make that method a bit simpler anyway.

@mrlem
Copy link

mrlem commented Dec 7, 2019

I feel the right way to achieve this would be put the target panel in a fullscreen container and let the layout do the positioning. However, this currently isn't a panacea: from what I gather in Lemur's code, it would prevent you from animating translations (due to a clash in layout vs animation mechanisms both intervening on the panel's local translation).

But I may be wrong, having only a fairly recent interest in Lemur 😛.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants