Thread Tools Display Modes
06/23/14, 12:58 PM   #1
SkOODaT
 
SkOODaT's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 58
GetStringWidth() Question

Lua Code:
  1. function OnTargetTest()            
  2. local NSize = ZO_TargetUnitFramereticleoverName:GetStringWidth(GetUnitName("reticleover"))
  3. d(NSize)
  4.                
  5. end
  6.  
  7. EVENT_MANAGER:RegisterForEvent("TargetMaintenance_T", EVENT_RETICLE_TARGET_CHANGED, OnTargetTest)

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.
  Reply With Quote
06/23/14, 01:23 PM   #2
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
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.
  Reply With Quote
06/23/14, 01:31 PM   #3
SkOODaT
 
SkOODaT's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 58
Originally Posted by ingeniousclown View Post
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.
"***: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
  Reply With Quote
06/23/14, 02:01 PM   #4
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
I saw method label:GetStringWidth(text) just in case of indent:
Lua Code:
  1. function zo_bulletFormat(label, text)
  2.     local bulletSpacer = GetString(SI_FORMAT_BULLET_SPACING)
  3.     local bulletSpacingWidth = label:GetStringWidth(bulletSpacer)
  4.     label:SetNewLineX(bulletSpacingWidth)
  5.     label:SetText(zo_strformat(SI_FORMAT_BULLET_TEXT, text))
  6. end

Try to use something like:
Lua Code:
  1. label:SetText(text)
  2. label:SetDimensions(label:GetTextDimensions())
  Reply With Quote
06/23/14, 02:27 PM   #5
SkOODaT
 
SkOODaT's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 58
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.
  Reply With Quote
09/18/15, 07:13 PM   #6
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
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?
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » GetStringWidth() Question


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off