getWidth() does not correspond to retina resolution?

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.


1 Like

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.

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.

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

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

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

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

find the display, where your Component shows. Note: to interact with the Display, use the singleton Desktop::getInstance()

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

Oh man it’s crazy :slight_smile: , 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.

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 :slight_smile: Sorry for that. I’d just seen the link and immediately jump there and did not notice your line of code.

But there is still something wrong.
It gives me 144. But according to documentation of Macbook Pro 13 late 2012 it is 227.
And that:
Should give me 2560. But it displays the value which is here:

So how to get real physical number of pixels?

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.

1 Like

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.