Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: jmorhart on February 27, 2015, 07:49:18 PM
-
Hi all,
I would like to know if there is a way of scaling UIWidgets based on the screen DPI? I understand that the entire UI can be scaled that way by setting the UIRoot's scaling style to Flexible and checking Adjust By DPI. However, I want the majority of my UI to be Constrained, and have just a few UIWidgets scale based on DPI. Any ideas how I would go about doing this? Thanks!
-
You'd have to write code for that. Have a look at what "adjust by DPI" setting does and do something similar in a script attached to one or more of your widgets.
-
I figured I'd have to write some code, and I'm fine with that. I think I explained myself poorly as well. What I'd really like to do is scale a UIWidget based on a physical size. For example, make a UIWidget take up 1 inch on the screen no matter what the UIRoot's scaling mode is set to.
-
Yeah it's just a matter of math. Knowing the screen DPI and the desired size, calculate the size of the widget.
Just keep in mind screen DPI is not reliable. There is no 100% case where you can have something be 1 inch on every device.
-
Yep, that part I understand. Physical Size * DPI = size in pixels. So a 1" physical size @ 96 DPI = 96 pixels. The problem is that I have my UI's scaling style set to constrained by height, so that means it's using 96 virtual pixels. How do I convert those virtual pixels to physical pixels?
-
Figured it out, just had to wrap my head around the math :p Some pseudo code:
physicalPixels = sizeInInches * DPI
physicalPercent = physicalPixels / screenHeight;
spriteHeight = physicalPercent / uiRootActiveHeight;
Hope this can help someone else!