06/23/14, 12:58 PM | #1 |
GetStringWidth() Question
Lua Code:
why does this spit out 49 on a 6 space name lol it seems like its bugged ... i need it to set ***:SetDimensions(NSize,15) for a Name text field Im looking at an NPC right now with that function the NPC name is "Riina Balen" - 11 Spaces but with the above function its saying its 85?!?!? lol Last edited by SkOODaT : 06/23/14 at 01:03 PM. |
|
06/23/14, 01:23 PM | #2 |
|
Just looking at the numbers, it looks like pixel (or UI unit, in ESO's case) width that the string takes up.
Based on that assumption, "***:SetDimensions(NSize,15) for a Name text field" will probably do exactly what you want it to do. |
06/23/14, 01:31 PM | #3 |
"***:SetDimensions(NSize,15) it doesnt tho i get extra space on both ends :S even tried :gsub("^%s*(.-)%s*$", "%1") to trim all the blank space
|
|
06/23/14, 02:01 PM | #4 |
I saw method label:GetStringWidth(text) just in case of indent:
Lua Code:
Try to use something like: Lua Code:
|
|
06/23/14, 02:27 PM | #5 |
label:SetText(text)
label:SetDimensions(label:GetTextDimensions()) works great except the space is still there lol i found local NSize = string.len(TMTargetRName) calculates the spaces correctly BUT TargetMaintenanceName:SetDimensions(NSize,15) its not applying to its not adjusting the space even though NSize has the correct var being applyed to it.... im getting lost lol i think something in my addon is stealing or adding space im just not sure lol Last edited by SkOODaT : 06/23/14 at 02:31 PM. |
|
09/18/15, 07:13 PM | #6 |
|
Necroing an old thread, because I have a related question.
I use GetStringWidth to make labels just a little bit wider than the text they contain (here). Today I noticed that with UI scale other than 1 the width is not correct -- with scale < 1 the text is too wide, it doesn't fit; with scale > 1 the control is too wide. Does GetStringWidth return width in pixels instead of UI units? |
09/18/15, 08:32 PM | #7 |
|
If the tabControl has a scale applied to it then it also scales the text by that amount.
So as an example, if you have a label with a scale of 1.5 and you put text in it that has an actual width of 100 (with a scale of 1.0), the text will get scaled up to 100 * 1.5 = 150. But the real problem looks like the GetStringWidth() function also applies the scale to the returned value: Lua Code:
It actually returns the actual text width * 1.5 * 1.5. The first multiplier is from the label being scaled which also scaled the string. The second multiplier is coming from the GetStringWidth() function applying another 1.5 multiplier to the returned width. Since the text width was already scaled I don't know why it would do that, but that is what it looks like its doing. So you need to get the string width before you scale the control or adjust the width after you get it. Lua Code:
EDIT: I forgot to add, the reason you want the real text width (on a scale of 1.0) is because when you use SetWidth(width) it applies the scale to the width that you pass into it. So if the label has a scale of 1.5 and you do Lua Code:
Last edited by circonian : 09/18/15 at 08:51 PM. |
09/19/15, 05:06 AM | #8 |
|
Yes, that's what I suspected. It seemed weird that I needed to un-scale the returned value before passing it to SetWidth. GetStringWidth is only used in conjunction with SetNewLineX in ZO code, maybe they both work with pixels.
Edit: I don't think it multiplies twice by the scale. If the text width is 100 UI units and GetStringWidth returns 150 pixels, but I use the value as UI units in SetWidth(150), the control width will end up being 225 pixels. I only considered the global scale, didn't check whether the control's scale is applied. This is my modified code, seems to work ok so far: Lua Code:
Last edited by merlight : 09/19/15 at 05:15 AM. |
09/19/15, 02:06 PM | #9 |
|
Ah, I only looked at the controls scale I didn't look at the global UI scale.
Your right, the global scale appears to work differently. Although I'm not sure how. It does not appear to change the control width, it does return a scaled GetStringWidth(), but it does not appear to be a factor of the GetGlobaUIScale(), & it has no effect on SetWidth(). I was using this to examine the values:
Warning: Spoiler
Lua Code:
But that would mean if your only using a global ui scale you shouldn't need to divide by GetGlobalUIScale(). Because GetStringWidth() returns the scaled width and setWidth is not effected by the GlobalUIScale. It works for me without it? Are you using both a globalUIScale & a scale on the control? It is multiplied twice though using the controls scale.
Warning: Spoiler
Lua Code:
|
09/19/15, 03:04 PM | #10 |
|
Just looked at an inventory label containing "Keep Wall Masonry Repair Kit"
Lua Code:
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. |
09/19/15, 03:16 PM | #11 |
|
That 1.19 is... unexpected. Maybe it also depends on the selected font. They may not scale smoothly but find closest matching font size and use that...
|
09/21/15, 11:10 AM | #12 |
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. |
|
09/21/15, 05:50 PM | #13 |
|
Thanks for the clarification.
|
02/12/16, 12:44 AM | #14 | |
|
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:
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:
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:
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:
And if he did mean the literal returned value of GetWidth() then why are none of these ever equal: Lua Code:
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. |
|
ESOUI » Developer Discussions » General Authoring Discussion » GetStringWidth() Question |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|