I don't like TextScaled

This issue can’t be resolved by the TextScaled property. I want the text to remain consistent across different resolutions without having to make it as large as it is in a text label when TextScaled is enabled. You might suggest using UITextSizeConstraints, but that makes a text size of 15 on 1080p that looks good, look incredibly small on 4K. On 4K screens, a text size of 15 becomes unreadable, while on 1080p it is the desired proportions.

My current solution to this is to update the size of text in textlabels based on the size of the screen every time it changes:

local function FixTextSizes()
	local ScreenSize = Main.AbsoluteSize
	local MinDimension = math.min(ScreenSize.X, ScreenSize.Y)
	for _, Item in ipairs(Main.PlayerList:GetDescendants()) do
		if Item:IsA("UITextSizeConstraint") then
			local NewSize = math.clamp(MinDimension / 65, 4, 20)
			Item.MinTextSize = NewSize
			Item.MaxTextSize = NewSize
		elseif Item:IsA("UIStroke") and Item.Parent.Name == "PlayerName" then
			Item.Thickness = math.clamp(MinDimension / 432, 0.1, 1.25)
		elseif Item:IsA("UIStroke") and Item.Parent.Name == "PlayerLevel" then
			Item.Thickness = math.clamp(MinDimension / 432, 0.1, 2.25)
		elseif Item:IsA("UIListLayout") and Item.Parent.name == "PlayerList" then
			Item.Padding = UDim.new(0, math.clamp(MinDimension / 1080, 0, 100))
		end
	end
	for _, Item in ipairs(Main.Chat.ChatsBox:GetChildren()) do
		if Item:IsA("TextLabel") then
			local NewSize = math.clamp(MinDimension / 65, 1, 100)
			Item.TextSize = NewSize
		end
	end
end

Am I stupid? Is there something I don’t know about UI that does exactly what I want for me? Or is this the correct solution. If I need to further elaborate what I’m doing or what’s desired, I will, feel free to ask.

p.s. I apologize if this is not the correct thread for this.

2 Likes

The non-code way of doing what you want is just to have the y-size of the text label be sufficiently small, such that the text size becomes what you want it to. If you want to have multi-line text, you could try putting new lines (\n) into the text to force it to split text over multiple lines.

Some are multi line labels, where I use AutomaticSize to dictate that, but that is independent of TextScaled and so I end up needing to set the size of the text.

Does adding a UIPadding parented to the TextLabel fix the issue? It’s basically a way to offset UIs. On TextLabels, it adds padding to the text. This also works with TextScaled enabled.

That’ll simply reposition it, which is not the desired effect…? Or am I wrong?

It adjusts the text bounds for TextLabels, so they’ll fit in the frame better if you customize it. There are left, right, top, and bottom boundaries, all with UDim type properties for scaling and offsetting.

This is one of the UI modifiers that have multiple functions. Another example is UIGradients on UIStrokes.

There’s also a cool combo of adding both a UICorner and UIStroke into a frame to add an anti-aliasing effect for rotated GUIs.

This is something I forgot to ask about in the AMA.

Unfortunately, there’s currently no built-in way of handling this that I know of. Eventually I want to create some sort of permanent solution with a plugin. But in the meantime, here’s what I normally do:

local numberOfLines = 10
TextLabel.TextSize = math.round(TextLabel.AbsoluteSize.Y/numberOfLines)

But you might want to turn on TextScaled if it goes beyond the text area, which you can do by comparing TextLabel.TextBounds to TextLabel.AbsoluteSize.

I’d also recommend attaching this to TextLabel:GetPropertyChangedSignal('AbsoluteSize'), that way it can update whenever the window size changes or if the TextLabel’s size changes for any reason.

1 Like

This isn’t a very efficient way to do it but you could just layer a smaller TextLabel over whatever GUI you are using. A button with an unselectable TextLabel above it should be the same as a TextButton.

In my experience using Paddings, they’ve just offset the position of the text inside the label.

That is incredibly redundant, and I shouldn’t have to do that. I think i’d much rather have a script rather than need to account for and reference additional textlabels simultaneously

Try adjusting both the left and right padding and see that it actually borders the text scale instead of the text position.

With the current label, I’m playing with, adjusting the right padding doesn’t do much since text is aligned with the left edge of the label.
image

How about the left padding? It should set the left border into the left padding’s UDim property.

Well prior to the discussion about UIPadding’s, I was already using one to offset the text slightly so that the text doesn’t hug the edge of the text label.
image
image

How about adjusting the top and bottom border then to achieve your TextScaled offset? Also, here’s the documentation for UIPadding. It doesn’t offset the position, instead it offsets the border.

1 Like

This is how I’ve done it for my custom ui framework

local function WrapText(ProxyTable, TextSize)
		for i = 2, 51 do 
			if ProxyTable.Instance.TextFits then return end
			local _TextSize = (TextSize + 2)//i -2 -- 2 is "padding", to make the text wrap properly. This should also be harded into the Sizeing function of the Theme
			ProxyTable.Instance.TextSize = _TextSize
		end

		if ProxyTable.Instance.TextFits then return end

		warn("Unable to make text of "..ProxyTable.Instance.Name.." fit within the frame. Limit of 50 lines reached. Target TextSize: "..TextSize)
	end

Basically, the text has a TextSize it tries to match, usually half the y size of my frames (well my frames all have the same y size, but that textsize can be constant for all your frames). If the text doesn’t fit, the size is reduced by half, until it fits
TextWrapped is also enabled, for multi line text, something you can’t do with TextScalled

In my opinion, roblox’s scripless ui system is just not quite good enough to make dynamic and high quality ui. It’s good for easily making ui that is “good enough”, but if you want more, you have to script it, either by putting scripts under a bunch of different instances which is a pain, scripting the whole thing by hand which leads to extremely long scripts, or making a ui framework that is quite complex. At least that is my personal experience with ui

1 Like

This is why I’d recommend a plugin that could automate that process in some way. Maybe one that adds a script when you add a particular attribute to a TextButton/TextLabel and removes it if the attribute is removed. Not the cleanest experience, but it would be quick and easy enough to do I suppose.

It would be infinitely better if we could just have custom classes. Though sadly that won’t be happening anytime soon: