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:
d("************************")
SetSetting(SETTING_TYPE_UI, UI_SETTING_CUSTOM_SCALE, 1.0)
ApplySettings()
local text = "test................."
local label = TestControl
label:SetScale(1.0)
local width = label:GetStringWidth(text)
d("GlobalScale: "..GetUIGlobalScale()) -- 1
d("StringWidth: "..width) -- 99
d("ControlWidth: "..label:GetWidth()) -- 222.75
SetSetting(SETTING_TYPE_UI, UI_SETTING_CUSTOM_SCALE, 1.1)
ApplySettings()
d("** After Global Scale 1.1")
local width = label:GetStringWidth(text)
d("GlobalScale: "..GetUIGlobalScale()) -- 1.1
d("StringWidth: "..width) -- 118 (scaled by approx. 1.19 ?)
d("ControlWidth: "..label:GetWidth()) -- 222.75 (unchanged)
d("** SetWidth to: "..width)
label:SetWidth(width)
d("ControlWidth: "..label:GetWidth()) -- 118 (this should be the correct width)
-- without dividing by GlobalUIScale()
-- If your not also using a control scale
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:
d("************************")
SetSetting(SETTING_TYPE_UI, UI_SETTING_CUSTOM_SCALE, 1.0)
ApplySettings()
local text = "test................."
local label = TestControl
label:SetScale(1.0)
local width = label:GetStringWidth(text)
d("LabelScale: "..label:GetScale()) -- 1
d("StringWidth: "..width) -- 99
d("ControlWidth: "..label:GetWidth()) -- 222.75
d("** After Control Scale 1.5")
label:SetScale(1.5)
local width = label:GetStringWidth(text)
d("LabelScale: "..label:GetScale()) -- 1.5
d("StringWidth: "..width) -- 222.75 (stringWidth is scaled by * 1.5 * 1.5)
d("ControlWidth: "..label:GetWidth()) -- 334 (control width gets scaled, unlike changing the globalUIScale)
d("** Adjusted the width: width / (1.5 * 1.5)")
width = width / (1.5 * 1.5)
d("Adjusted Width: "..width) -- 99 (actual text width)
d("** SetWidth")
label:SetWidth(width) -- Setting it to 99, but it gets scaled:
d("ControlWidth: "..label:GetWidth()) -- 148.5 (gets scaled back up to the "scaled" text width)