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

**URL:** <https://forum.juce.com/t/correct-way-to-resize-a-window-keeping-the-content-component-aspect-ratio/31653>\
**Category:** General JUCE discussion\
**Created:** [February 7, 2019, 12:51pm UTC](https://forum.juce.com/t/correct-way-to-resize-a-window-keeping-the-content-component-aspect-ratio/31653 "2019-02-07T12:51:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nonlethalapplications](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nonlethalapplications/32/10298_2.png) [@nonlethalapplications](https://forum.juce.com/u/nonlethalapplications)\
**Post date:** [February 7, 2019, 12:51pm UTC](https://forum.juce.com/t/correct-way-to-resize-a-window-keeping-the-content-component-aspect-ratio/31653/1 "2019-02-07T12:51:41Z")

</div>

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);
_miniPlayerWindow->getConstrainer()->setFixedAspectRatio(ratio);
_miniPlayerWindow->setSize(500,500/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?

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [February 7, 2019, 3:01pm UTC](https://forum.juce.com/t/correct-way-to-resize-a-window-keeping-the-content-component-aspect-ratio/31653/2 "2019-02-07T15:01:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nonlethalapplications](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nonlethalapplications/32/10298_2.png) [@nonlethalapplications](https://forum.juce.com/u/nonlethalapplications)\
**Post date:** [February 7, 2019, 5:11pm UTC](https://forum.juce.com/t/correct-way-to-resize-a-window-keeping-the-content-component-aspect-ratio/31653/3 "2019-02-07T17:11:44Z")

</div>

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:  
[https://1drv.ms/u/s!AiJDLKXxYWMYhjLUlMCI3\_5qE9nM](https://1drv.ms/u/s!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!
