View Single Post
02/12/16, 12:44 AM   #14
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by ZOS_ChipHilseberg View Post
GetWidth() = GetStringWidth() / GetGlobalUIScale()
GetWidth() = GetTextWidth() * GetScale()

There was a bug where scale was being double applied in GetStringWidth() (once to each character and once to the total) that is now fixed.
Question 1: What is the proper way to calculate a strings width/height for setting a label controls dimensions (taking possible scaling into account)?
I'm assuming in Chips statement that by GetWidth() = ... he meant that the correct width for the control is = .... and not the actual returned value of GetWidth(), but either way it doesn't seem to add up.

Question 2: Do I missunderstand Chips statement, because it does not seem to always be correct? There must be more to it...or a bug?
By Chips statement then the following should be true?
Lua Code:
  1. GetWidth() = GetStringWidth() / GetGlobalUIScale() = GetTextWidth() * GetScale()
  • But none of them are equal if the control is scaled.
  • Only the first 2 are equal if GetScale() = 1 and the control is to small to display all of the text.
  • All 3 are equal if GetScale() = 1 and the control is large enough to display all of the text.
Why?

If GetScale() = 1.5 and the control is large enough to display all of the text before measuring we get these measurements:

None of these are equal and none are the correct width for setting the labels width:
Lua Code:
  1. GetWidth() = GetStringWidth() / GetGlobalUIScale() = GetTextWidth() * GetScale()
In this case the correct values for setting the controls dimensions are given by GetTextHeight() & GetTextWidth() <without multiplying by * GetScale()> and notice that GetStringWidth() / GetGlobalUIScale() does not give the correct width for the control (the correct width is 220.xxx).


If GetScale() = 1.5 and the control is to small to display all of the text before measuring we get these measurements:

None of these are equal and none are the correct width for setting the labels width:
Lua Code:
  1. GetWidth() = GetStringWidth() / GetGlobalUIScale() = GetTextWidth() * GetScale()
In this case GetTextHeight() is still the correct height, but none of the values reveal the correct width that needs to be set on the control (the correct width is 220.xxx).


Question 3: In the two pictures above notice that the StringWidth measurements are consistent, but the TextWidth measurements are not. Why?

It appears GetTextWidth() only measures the visible text that is not cut off due to the control being to small. If when Chip used GetWidth() he was actually refering to the returned value of GetWidth() and not the "correct value" that should be used for setting the control width, then given his equations that would make sense, but if we solve both equations for the respective functions:
Lua Code:
  1. GetStringWidth() = GetWidth() * GetGlobalUIScale()
  2. GetTextWidth() = GetWidth() / GetScale()
Then shouldn't both functions be effected by the actual width of the control returned by GetWidth()?
And if he did mean the literal returned value of GetWidth() then why are none of these ever equal:
Lua Code:
  1. GetWidth() = GetStringWidth() / GetGlobalUIScale() = GetTextWidth() * GetScale()


Question 4: Why is GetTextWidth effected by the controls width, but GetTextHeight does not appear to be effected by the controls height?


If GetScale() = 1 and the control is to small for the text to be displayed:


This time GetTextWidth() is incorrect, GetStringWidth() / GetUIGlobalScale() returns the correct control width, and GetTextHeight() returns the correct height. I would have assumed that whatever the differences are between GetStringWidth & GetTextWidth that the two GetTextXXXX() functions would both work in the same way, but I guess not because GetTextHeight() seems to always return the correct height for the control, but GetTextWidth() does not <not even when scaled: * GetScale()>


If GetScale() = 1 and the control is large enough to display all of the text, this is the only time that Chips statement seems to be true:



Regardless of any of the above settings, these always appear to be the correct dimensions to use with SetWidth() & SetHeight() (for this example text):



If I reduce the width by just 1, we can see the last letter gets cut off, so 221 was the correct width to use, but
Question 5: Why doesn't reducing the height cut off any text?


I'm assuming whatever the answer is to this question it is the same reason why GetTextHeight() always returns the correct value, but it would be nice to know why.

Last edited by circonian : 02/12/16 at 01:39 AM.
  Reply With Quote