Correct way to resize a window keeping the content component aspect ratio

I have a native window (macOS) showing a video in the content component and I want it to keep the original aspect ratio of the video when being resized.

I tried a solution I found here in the forum and it works per se:

double ratio = resolution.width/resolution.height;
_miniPlayerWindow->setResizeLimits(300, 300/ratio, 1500, 1500/ratio);

However, this doesn’t take the window title bar into account so I’m getting borders on the left and right as the aspect ratio is only correct for the content, not the content + the title bar. It looks like there’s no way to query that. I tried DocumentWindow::getTitleBarHeight() and it returns 0 for native windows.

Is there a quick and easy approach to this?
I tried setting a fixed size for the title bar but it looks like I can’t get the right value.
Is there a way to attach a constrainer to the content component and make the window use that when resizing?

You can use ComponentPeer::getFrameSize() to get the frame size of the native window including the title bar.

1 Like

Thanks for your reply!
Unfortunately that didn’t fix the issue.
It looks like setting the aspect ratio doesn’t work properly.

I uploaded a simple sample project here:!AiJDLKXxYWMYhjLUlMCI3_5qE9nM

As you can see, the aspect ratio is set to a value but that value changes when the window is resized and isn’t constant. Tested on 10.14.
I couldn’t find out where this happens immediately.
Can you help?

Thanks in advance!