Problems with ComponentBoundsConstrainer and fixed aspect ratio

#1

I’m trying to limit a resizable window to a fixed aspect ratio. I tried modifying the DemoRunner’s WindowsDemo::showDocumentWindow to use the simple BorderBoundsConstrainer class from here: Resizing a window with native titlebar and fixed aspect ratio

I added this to the end of showDocumentWindow

BorderBoundsConstrainer* constrainer = new BorderBoundsConstrainer();
constrainer->SetBorder(native ? dw->getPeer()->getFrameSize() : dw->getContentComponentBorder());
constrainer->setFixedAspectRatio(originalWidth/originalHeight);
dw->setConstrainer(constrainer);

When dragging the corner resizer, it works reasonably well for the native title bar case, but behaves very strangely (window position jumping around), when using the non-native titlebar.
Is there some other way I should be doing this?

Thanks,
John

0 Likes

#2

Turns out the constrainer doesn’t work so well with the native titlebar either. It seems to ignore setMinimumOnscreenAmounts.
As an experiment, I added constrainer->setMinimumOnscreenAmounts(0xffffff, 0xffffff, 0xffffff, 0xffffff); to the above example. The native case appears to ignore those minimumOnscreenAmounts, while the non-native case works properly.
Seems buggy!

Any suggestions?

Thanks,
John

0 Likes

#3

What platform is this on? Do you see the same behaviour using the standard ComponentBoundsConstrainer in JUCE?

0 Likes

#4

I’m on macOS 10.14.3 (18D109). JUCE latest 5.4.3.

Using the regular ComponentBoundsConstrainer is much less glitchy, but still occasionally bounces around a bit when dragging the corner resizer. Also, the setMinimumOnscreenAmounts still has no effect when using native titlebar.

Here’s my modified DemoRunner’s WindowsDemo.h, with modifications in showDocumentWindow starting at line 322: https://drive.google.com/open?id=1g37wdwDqMkQQKbLK3Ls60dF0Kl1mknwj

Here are two videos using ComponentBoundsConstrainer:

Note some glitchiness when resizing: https://drive.google.com/open?id=1OL7i2WKg-S1_f1ahjqQMFQaiRRiWVw9d

Note the native title bar minimumOnscreenAmounts are not working, while non-native title bar is staying on-screen properly: https://drive.google.com/open?id=1ZBEU3PZTeD9eFIdrzbgP7p4oXicVuNdU

And here’s a video of the resizing glitches using the BorderBoundsConstrainer:

Note the glitches when resizing the non-native title bar window: https://drive.google.com/open?id=1reXeDq3DVZ7pH8zkio4zTCe8iVe30QNK

I need to preserve the aspect ratio of the window content, not including the title bar. The obvious application is to put a photo in the content, and keep it scaled to fit the window entirely. I want the window content size to match the aspect ratio of the photo. Please advise how best to accomplish this.

Thanks,
John

0 Likes

#5

Any thoughts on this?
-John

0 Likes

#6

I don’t see any resizing glitches when using the ComponentBoundsConstrainer, but I can’t comment on the BorderBoundsConstrainer class that you are using.

The minimum onscreen amounts will take effect when you release the mouse on macOS when using the native title bar as this is when we get the callback from the OS to constrain the bounds. If you want to enforce an aspect ratio for the window content without the title bar then you can use ComponentPeer::getFrameSize() to get the native title bar size and subtract that from the content size to work out the aspect ratio that you need.

0 Likes

#7

Yes, using the peer’s getFrameSize() works ok for the native titlebar window, as I showed in my BorderBoundsConstrainer modification to the DemoRunner’s WindowsDemo.

But for a non-native titlebar window, I haven’t found a way to constrain it without it being very glitchy as I showed in the video. https://drive.google.com/open?id=1reXeDq3DVZ7pH8zkio4zTCe8iVe30QNK . What do you suggest? Do you have a working example of a fixed aspect ratio constrained non-native titlebar window which excludes the titlebar border from the ratio?

As for the regular ComponentBoundsConstrainer, you can see see a minor window-bouncing glitch at around the 2 second mark in my example video: : https://drive.google.com/open?id=1OL7i2WKg-S1_f1ahjqQMFQaiRRiWVw9d .

Thanks for the explanation of the minimum onscreen enforcement occurring on mouse-release for native titlebar window.

-John

0 Likes