# getWidth() does not correspond to retina resolution?

**URL:** <https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951>\
**Category:** General JUCE discussion\
**Created:** [October 20, 2018, 9:16am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951 "2018-10-20T09:16:05Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 9:16am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/1 "2018-10-20T09:16:05Z")

</div>

Hello,  
I have Macbook Pro 13 with retina display. And according to documentation it has 2560 x 1600 pixels. But when I set my `Component` window to `setSize(2560, 1600)` my window appears much bigger than my screen.  
So what exactly means one pixel in Juce? In other words:  
1 pixel in Juce is equal to how many real retina pixels?

Great thanks for any help in advance.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [October 20, 2018, 9:19am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/2 "2018-10-20T09:19:23Z")

</div>

`Desktop::getInstance().getDisplays().getMainDisplay().scale`

[https://docs.juce.com/master/structDesktop\_1\_1Displays\_1\_1Display.html](https://docs.juce.com/master/structDesktop_1_1Displays_1_1Display.html)

---

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 9:37am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/3 "2018-10-20T09:37:29Z")

</div>

OK, thanks but it doesn’t work for me.  
When I use `Desktop::Displays::Display::scale` I get error: Invalid use of non-static data member ‘scale’

So I tried to inherit my `AudioProcessorEditor` by `: public Desktop::Displays::Display`

But then `scale` is equal to zero.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 20, 2018, 9:43am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/4 "2018-10-20T09:43:06Z")

</div>

You can read this value. It is not meant for you to change it, since if you move your window from one screen to another, this value might change, but you still want your component to appear at the same size. The docs \_matkatmusic linked above state:

> If you create a component with size 1x1, this scale factor indicates the actual size of the component in terms of physical pixels. For higher-resolution displays, it may be a value greater than 1.0

For example, if it says 2.0, your Component’s getWidth() would be just half of your number of screen pixels to fill the screen.

---

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 9:44am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/5 "2018-10-20T09:44:15Z")

</div>

OK, but as I told, it says zero. So does it means my Component’s getWidth() would be infinity?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 20, 2018, 9:45am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/6 "2018-10-20T09:45:12Z")

</div>

Because by trying to inherit, you hid the actual value. Remove that.

---

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 9:46am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/7 "2018-10-20T09:46:00Z")

</div>

But how to get that real value?  
I tried also that:  
`Desktop::Displays::Display myDisplay;`

And then `DBG(myDisplay.scale);` and it gives me zero - `0`

---

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 9:55am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/8 "2018-10-20T09:55:25Z")

</div>

When I just use `DBG(Desktop::Displays::Display::scale);` I get error Invalid use of non-static data member ‘scale’

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 20, 2018, 9:58am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/9 "2018-10-20T09:58:22Z")

</div>

find the display, where your Component shows. Note: to interact with the Display, use the singleton [Desktop::getInstance()](https://docs.juce.com/master/classDesktop.html#a15ebe474aab368cff35578b8f7bec6c1)

```auto
auto display = Desktop::getInstance().getDisplays().findDisplayForRect (getScreenBounds());
DBG ("Scale is: " << display.scale);

```

But to be honest, you shouldn’t need to know about it, because the system is designed to avoid the need to deal with physical pixels, since they are different on each screen (even on the same machine). Just keep thinking in logical pixels and all is good.

Hope that helps

---

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 10:00am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/10 "2018-10-20T10:00:50Z")

</div>

Oh man it’s crazy 🙂 , how did you figure it out?  
I don’t want to use `scale` in any way. I just make my small investigation about my display.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [October 20, 2018, 10:29am UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/11 "2018-10-20T10:29:46Z")

</div>

I gave you the exact line of code required to get the current scale of your primary display… Why don’t you search the demo projects for that line to see how to use it?

---

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 12:04pm UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/12 "2018-10-20T12:04:47Z")

</div>

> [@matkamusic](#):
>
> I gave you the exact line of code required to get the current scale of your primary display… Why don’t you search the demo projects for that line to see how to use it?

Matka, yes you are right 🙂 Sorry for that. I’d just seen the link and immediately jump there and did not notice your line of code.

---

<div class="post-metadata">

**Author:** ![pajczur](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pajczur](https://forum.juce.com/u/pajczur)\
**Post date:** [October 20, 2018, 12:29pm UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/13 "2018-10-20T12:29:26Z")

</div>

But there is still something wrong.  
`Desktop::getInstance().getDisplays().getMainDisplay().dpi;`  
It gives me 144. But according to documentation of Macbook Pro 13 late 2012 it is 227.  
And that:  
`Desktop::getInstance().getDisplays().getMainDisplay().totalArea.getWidth()`  
Should give me 2560. But it displays the value which is here:

 ![46](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/7aa95cfcc7d8abbfd41b0f0a01db4331cc5b359e.jpeg)

So how to get real physical number of pixels?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 20, 2018, 12:53pm UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/14 "2018-10-20T12:53:50Z")

</div>

And you have set your display to “scaled”, so it reduces the dpi for logical pixels from the max possible 227 to 144, so the content appears bigger.

Little maths:  
2560 dots / 227 dots per inch = 11.27 inch (13" is diagonal)  
1680 dots / 144 dots per inch = 11.67 inch  
So probably there is a rounding in some of the values Apple specifies, but roughly the numbers add up.  
Try your test again with “Resolution: default for display” selected.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 20, 2018, 1:04pm UTC](https://forum.juce.com/t/getwidth-does-not-correspond-to-retina-resolution/29951/15 "2018-10-20T13:04:15Z")

</div>

> [@pajczur](#):
>
> So how to get real physical number of pixels?

Maybe there isn’t a physical number.  
Maybe the scale is a non-integer value  
Maybe your window is rotated at 20 degrees so that the physical pixels don’t even line up with the virtual ones.  
Maybe the resolution is so high that a human can’t even see the pixels.  
Maybe the display gets scaled in hardware so that the physical pixels it reports don’t actually correspond to the ones on the screen (this is common in phones)

I get so tired of these “physical pixel” questions - they always turn out to be someone trying to make some graphics fit the pixels on the display they’re currently staring at, without considering where else it might be used.

Physical pixels mattered in the 1990s when VGA was still a thing, but people have all kinds of displays now, you need to think about your graphics in a more abstract way.
