View Single Post
09/19/15, 03:04 PM   #10
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Just looked at an inventory label containing "Keep Wall Masonry Repair Kit"
Lua Code:
  1. GetUIGlobalScale() == 0.64
  2. label:GetScale() == 1
  3. label:GetTextWidth() == 229.6875
  4. label:GetStringWidth(label:GetText()) == 147 == 0.64 * 229.6875
  5.  
  6. GetUIGlobalScale() == 1.10
  7. label:GetScale() == 1
  8. label:GetTextWidth() == 223.6364
  9. label:GetStringWidth(label:GetText()) == 246 == 1.10 * 223.6364
  10.  
  11. GetUIGlobalScale() == 0.64
  12. label:GetScale() == 1.25
  13. label:GetTextWidth() == 229.6875
  14. label:GetStringWidth(label:GetText()) == 229.6875 == 0.64 * 1.25^2 * 229.6875
  15.  
  16. GetUIGlobalScale() == 1.10
  17. label:GetScale() == 1.25
  18. label:GetTextWidth() == 223.6364
  19. label:GetStringWidth(label:GetText()) == 384.375 == 1.10 * 1.25^2 * 223.6364

You were right about GetStringWidth being multiplied twice by the control's scale. That's really weird. Anyway, with control scale == 1 it's pretty clear that GetStringWidth returns pixels, while GetTextWidth returns UI units (unaffected by scaling).

In the meantime, I found a way around explicitly setting the width of the Label control -- SetWidth(0) and wrap it in a container with SetResizeToFitDescendents(true) and SetResizeToFitPadding(10, 0). Unfortunatelly that trick doesn't work for Button controls, so those still have to adjust to UI scale changes.
  Reply With Quote