Window size independent GUI

How are you attaching your DirectGUI widgets to the window? If you parent them below “aspect2d” (the default), then they should retain their size and position, I believe.

There is one catch, however: Their positions are held relative to the centre of the window. As a result, while a change to the size of the window should have little effect, a change to the aspect-ratio of the window may result in objects being shunted off-screen, or left adrift in empty screen-space.

Now, if your widgets are near the edge of the screen, then you can potentially remedy this by parenting them below a special set of anchors that Panda provides. These are located around the edge of the screen–one for the middle-left, one for the top-left, and so on. And, importantly, they automatically update their positions as the window is resized.

(These anchors are themselves children of “aspect2d”).

You can see a listing of the anchors here, I believe:

And to demonstrate, here is a simple example program:

from direct.showbase.ShowBase import ShowBase

from panda3d.core import TextNode
from direct.gui.DirectGui import *

class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        self.disableMouse()

        self.accept("escape", base.userExit)

        self.mew = DirectButton(scale = 0.1,
                                text = "Kitten",
                                parent = base.a2dTopLeft,
                                pos = (0, 0, -0.1),
                                text_align = TextNode.ALeft)

        self.mew2 = DirectButton(scale = 0.1,
                                text = "Cat",
                                parent = base.a2dRightCenter,
                                pos = (0, 0, -0.1),
                                text_align = TextNode.ARight)

app = Game()
app.run()
1 Like