setFixedAspectRatio and problem with standalone app because of native title bar Height

Happy new year 2024!

I have a problem with my project as a standalone application.

My DocumentWindow is set to resizable for responsive/scalable design with a constrainer.

I get my setFixedAspectRatio from the size of the container canvas. let’s say 600x400, W/H = 1.5

When I apply this ratio 1.5 to the standalone DocumentWindow, the ratio of the window is wrong because the native title bar height is included in the overall window size which makes its aspectRatio different from the inner canvas ratio.


The right way to get the appropriate ratio would be to get the inner content canvas height +nativeTitleBarHeight to determine the correct DocumentWindow aspectRatio.

Is it a common issue? Is there a way to get the native Title Bar Height (depending on the OS and if HDPI) ? Or is there a workaround for standalone apps to make it work?

Thanks for your help


I reply to myself:

I went with the ComponentPeer class:

vpOsFrameTop = getPeer()->getFrameSize().getTop(); // OS Native Title Bar Height
vpOsFrameBtm = getPeer()->getFrameSize().getBottom(); // OS Native Window Border Bottom thickness
vpOsFrameLeft = getPeer()->getFrameSize().getLeft(); // OS Native Window Border Left thickness
vpOsFrameRight = getPeer()->getFrameSize().getRight(); // OS Native Window Border Right thickness
vpOsWindowWidth = getPeer()->getBounds().getWidth(); // OS Native Window Height incl borders
vpOsWindowHeight = getPeer()->getBounds().getHeight(); // OS Native Window Height incl borders

double(vpStandaloneAspectRatio) = double(vpOsWindowWidth) / double(vpOsWindowHeight); // Requires Native Title bar Height and borders for standalone apps

        if (auto* constrainer = getConstrainer())
            constrainer->setFixedAspectRatio(vpStandaloneAspectRatio); // set window aspect ratio

// and so on...

This is working great, I had some trouble to get the perfect aspect ratio with the inner component and it was giving me scrollbars in my document

There’s also getTitleBarHeight() available for DocumentWindow class.

hope it helps