Author Topic: UITexture/Widget: How to maintain aspect ratio and detect portrait or landscape  (Read 3799 times)

vration

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Hi NGUI Support,

We're working on a project where we're pulling images from a server and displaying them inside a UIWidget, but encountering an issue with aspect ratio settings as it relates to detecting whether an image is in portrait or landscape size and scaling them appropriately.  We're also doing all the settings in Javascript, just FYI, hope that's not too much of an issue as I know NGUI prefers C# but we are not proficient in it. 

Currently we've managed to get the textures to anchor properly inside the UIWidget window and can force the aspect ratio, but we're having trouble finding anything in the documentation that would allow us to tell the system to check whether the texture has a larger width or height, and then based on which is the larger value apply an alternative aspect ratio. 

Please help?  Thanks in advance. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You mean like this? http://www.tasharen.com/forum/index.php?topic=2397.0

Basic Unity functionality lets you check Screen.width and Screen.height, and you can do what you want based on that.

vration

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Much thanks, I'll give that a shot.  My only concern is that's applying to UI Root.  We have a few different widgets in here and we need this to apply to just the UITexture that's loading inside one of the UIWidget functions.  Would the same language apply?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIRoot would affect everything, not just textures -- which is generally what you want. Otherwise you will need to write a script doing your own Screen.width and Screen.height checking logic.