Scaling text manually?

Hey, and thanks for reading in advance. My question is mostly in the title.

I’m using the Rich Text beta feature to format the description boxes for the abilities of the classes in a fighting game I’m helping to code.

The feature does not currently support the TextScale property, so I’ve been forced to use a little trickery to do so myself.

GUI_RATIO = UI.Main.AbsoluteSize.X/480
GUI_RATIO = (GUI_RATIO + UI.Main.AbsoluteSize.Y/96)/2
	
UI.Main.Tooltip.TextSize = math.ceil(24 * GUI_RATIO)
UI.Main.AltTip.TextSize = math.ceil(24 * GUI_RATIO)

This works fine, until I’ve got too much text to fit in the box:

Is there something I can add to my current code that would allow me to factor in the boundaries of the textbox? I can’t help but feel like the math on this is easier than I’m making it out to be, but I just want to be sure.

Any help is appreciated!

You can try using a UITextSizeConstraint.

1 Like

There’s a function that “Computes the Vector2 dimensions (in pixels) that will be taken up with text when using the specified formatting parameters and size constraints.”

1 Like

Would that return an accurate result in accounting for the formatting code that doesn’t get displayed when parsed by the Rich Text feature?

It would be accurate if you used a version of a string without the formatting code.

I see. I don’t think that’s something I can do, seeing as the metadata comes with some pre-written formatting code aside from what’s automatically added by the client.

local Abilities = {
	PSV = {
		ToolTip = '[PSV]: Battle Spirit - You gain <font color="rgb(0, 255, 255)">Shield</font> equal to 1/3 of damage you deal.',
		Icon = 3637961361,
		CurrentCD = 0,
		--
		Variance = {
			MaxCD = 0,
			Ratio = .3
		}
	},
	ATK = {
		ToolTip = '[ATK]: Brave Blade (#vMaxCD) - Slash with your weapon, dealing #vDamage damage.',
		AltTip = "[ALT]: Hero Surge - Perform a spinning cut that deals #vAltDamage damage. Activated during Blade Rush. Increases Blade Rush CD by 1s.",
		Icon = 2034108791,
		CurrentCD = 0,
		Loose = false,
		CoolAfter = false,
		--
		Variance = {
			MaxCD = 5,
			Damage = 15,
			AltDamage = 20,
		}
	},
	AB1 = {
		ToolTip = "[AB1]: Blade Rush (#vMaxCD) - Briefly boost speed and jump height. Allows running on water while active.",
		Icon = 2034172129,
		CurrentCD = 0,
		Loose = true,
		CoolAfter = true,
		--
		Variance = {
			MaxCD = 40,
			BuffPower = 2,
			BuffLength = .9
		}
	},
	AB2 = {
		ToolTip = "[AB2]: Slashing Waves (#vMaxCD) - Release two waves of energy that deal #vDamage damage each.",
		Icon = 2034172262,
		CurrentCD = 0,
		Loose = false,
		CoolAfter = false,
		MultiHit = true,
		--
		Variance = {
			MaxCD = 40,
			Damage = 6,
		}
	},
	CRT = {
		ToolTip = "[CRT]: Maelstrom - Release 3 columns of energy that travel forward, dealing #vDamage damage each to all foes in their path.",
		Icon = 4471228632,
		CurrentCD = 0,
		Loose = false,
		CoolAfter = false,
		--
		Variance = {
			MaxCD = 5,
			Damage = 15,
		}
	},
}

I’ll keep looking, though.

A dumb, hacky solution:

for size = 24, 0, -1 do
	GUI_RATIO = UI.Main.AbsoluteSize.X/480
	GUI_RATIO = (GUI_RATIO + UI.Main.AbsoluteSize.Y/96)/2
	
	UI.Main.Tooltip.TextSize = math.ceil(size * GUI_RATIO)
	UI.Main.AltTip.TextSize = math.ceil(size * GUI_RATIO)
		
	if UI.Main.Tooltip.TextFits and UI.Main.AltTip.TextFits then
		break
	end
end