Allow window resizing but lock aspect ratio and min/max window size?

Please let me know if Panda supports these or a custom task is needed to be written.
Regarding aspect ratio there’s an undocumented prc configuration called “aspect-ratio” which expects a float value which I assumed preserves aspect ratio when window resizing is enabled but it seems to do something else I didn’t understand.

Regarding setting a minimum and maximum window sizes, I think this is a very simple thing 99% programs that allow window resizing need, but I couldn’t find a ready function or prc configuration that does that.

While a custom task could be easily written for both I’d like to avoid unnecessary code if Panda already provides a solution.


Hmm it’s actually a few lines of code, which is very easy to implement as you’ve noticed. I don’t see any obstacles to the custom function.

Well other than non elegant (unnecessary) code, there’s also a minor visual issue. If you do in a task, the user can still resize the window to any aspect and size and the aspect ratio and resolution snap to the limited values set only after the mouse button is released.
I see no way to avoid this since taskMgr seems to stop when window is being resized.

Indeed, it is. I made a short code that demonstrates the problem. It seems that this is a real problem, although at first glance it seemed a trifle.

from direct.showbase.ShowBase import ShowBase

class Demo(ShowBase):

    def __init__(self):

        self.accept('window-event', self.resize_window)

    def resize_window(self, win = None):

        print ("resize")
demo = Demo()

This function does not work when changing the window because it has lost focus.

We’re limited by what the operating systems let us do. Window manager APIs do not have a way to let us lock in a particular aspect ratio. We would have to implement it ourselves via a hack, but this is trickier than it sounds at first. Also, we can only request a particular size of the window manager, and it’s not at all guaranteed to honor our requests, so if we implemented this we’d probably end up inviting a bunch of bugs that will occur on various systems in various corner cases.

I recommend, instead, using the letterboxing functionality in Transitions (or rolling your own by resizing the display regions).

If you think you absolutely need to have Panda implement an aspect ratio lock on window resizing, then please put in a feature request in the issue tracker.

Interesting but wxWidgets somehow does it. I know for sure that there are no problems with the event when the window changes.


By the way, if you need a quick solution, you can use wxWidgets by embedding the Panda3D window in It. It certainly looks like the invention of the wheel…

Oh, I’m sure it’s possible, with enough careful work and testing, to construct code that will adjust the window size to match a given aspect ratio. I’m just asking you to think carefully whether you can’t solve this problem in some other way (eg. letterboxing) before we add another potential bug nest to Panda.

If you do know for sure that you will need it, I am still open to adding it, if you file a request in the issue tracker.

It’s not a huge issue that makes a game or 3d GUI tool unusable but it does make it look unprofessional. In not many, but in some real cases people may not use Panda3D because of this, specifically commercial software where visual polish may be essential.