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
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?
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!
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.
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.
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.
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?