Device independent pixels

Just starting out? Need help? Post your questions and find answers here.
mdp
Posts: 31
Joined: Fri Oct 06, 2017 10:37 am

Device independent pixels

Post by mdp »

To use device independent pixels (DIPs) for the coordinates, do you make an explicit calculation (e.g. width/density) or is there a systemic way?
mdp
Posts: 31
Joined: Fri Oct 06, 2017 10:37 am

Re: Device independent pixels

Post by mdp »

I was expecting to find something like GetScreenDensity() in either Desktop or System, I was surprised not to find it.

A 5'' device can have a long side of 640, or 1280, or 2560px, or other, and a desktop screen can easily be around 96ppi. This means ppi measures of, for example, 96ppi, 160ppi, 320ppi, 640ppi - roughly 6 times between these two extremes, and since we are talking of areas perceptually one element can occupy 30 or 40 times the space it takes on another device.
123 pixels on one device can be tiny, on another huge.

SB must have a way to abstract size, either with an internal transformation (e.g. use 2 real pixels per virtual pixel where 2 is internally computed as Round(detected_density/base_density), ), or letting the coder do it "manually" through a command like GetScreenDensity() .
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: Device independent pixels

Post by falsam »

mdp wrote:A 5'' device can have a long side of 640, or 1280, or 2560px, or other, and a desktop screen can easily be around 96ppi. This means ppi measures of, for example, 96ppi, 160ppi, 320ppi, 640ppi - roughly 6 times between these two extremes, and since we are talking of areas perceptually one element can occupy 30 or 40 times the space it takes on another device.
Can you test this code with an Android terminal ? http://forums.spiderbasic.com/viewtopic.php?f=13&t=1288

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
mdp
Posts: 31
Joined: Fri Oct 06, 2017 10:37 am

Re: Device independent pixels

Post by mdp »

falsam wrote:Can you test this code with an Android terminal ? http://forums.spiderbasic.com/viewtopic.php?f=13&t=1288
This is great, it works!

So the idea is to use a
screen_density = 0
!v_screen_density = window.devicePixelRatio;


and you lock the zoom with both
!$('head').append('<meta name="viewport" content="width=device-width, maximum-scale=1.0, user-scalable=0">');
and
!document.body.style.zoom = 1 / window.devicePixelRatio * 100 + "%"
Post Reply