Automatic Canvas size not working

Yeah, I wouldn’t rely on this. It kinda doesn’t work for editing the middle of text… Hmmmmmmm

what do you mean?

asd

It bugs out when adding text to anywhere that isn’t at the end.

oh, is there anything I can do to fix it?

Here is a fix. This works around the issue of AutomaticSize being constrained to its Parent size with TextWrapping enabled. Its basically just a manual AutomaticSize.

local AutoScrollToBottomY = true
local ScreenGUI = script.Parent.Parent.Parent
local AllChildren = ScreenGUI:GetDescendants()
for i,v in pairs (AllChildren) do 
	if v:IsA("ScrollingFrame") then 
		if v:FindFirstChildOfClass("UIListLayout") or v:FindFirstChildOfClass("UIGridLayout")then
			local Layout = v:FindFirstChildOfClass("UIListLayout") or v:FindFirstChildOfClass("UIGridLayout")
			local function UpdateSize(FrameInstance,LayoutInstance)
				if FrameInstance and LayoutInstance then
					local PaddingX = 0
					local PaddingY = 0
					if FrameInstance:FindFirstChildOfClass("UIPadding") then
						local UIPadding = FrameInstance:FindFirstChildOfClass("UIPadding")
						PaddingX += UIPadding.PaddingLeft.Offset
						PaddingX += UIPadding.PaddingRight.Offset
						PaddingY += UIPadding.PaddingBottom.Offset
						PaddingY += UIPadding.PaddingTop.Offset
					end
					if FrameInstance.AutomaticCanvasSize == Enum.AutomaticSize.Y then
						FrameInstance.CanvasSize = UDim2.new(0,0,0,LayoutInstance.AbsoluteContentSize.Y + PaddingY)
					elseif FrameInstance.AutomaticCanvasSize == Enum.AutomaticSize.X then
						FrameInstance.CanvasSize = UDim2.new(0,LayoutInstance.AbsoluteContentSize.X + PaddingX,0,0)
					elseif FrameInstance.AutomaticCanvasSize == Enum.AutomaticSize.XY then
						FrameInstance.CanvasSize = UDim2.new(0,LayoutInstance.AbsoluteContentSize.X + PaddingX,0,LayoutInstance.AbsoluteContentSize.Y + PaddingY)
					end
					if AutoScrollToBottomY then
						v.CanvasPosition = Vector2.new(0,v.AbsoluteCanvasSize.Y - v.AbsoluteWindowSize.Y)
					end
				end
			end
			UpdateSize(v,Layout)
			Layout.Changed:connect(function() UpdateSize(v,Layout) end)
			v:GetPropertyChangedSignal("AutomaticCanvasSize"):connect(function() UpdateSize(v,Layout) end)
		end
	end
end

for i,v in pairs (AllChildren) do
	if( v:IsA("TextBox") or v:IsA("TextLabel") or v:IsA("TextButton") ) and v:GetAttribute("CustomAutoSizeY") == true then
		local TextBox = v
		local Spacing = 1.20
		TextBox.TextWrapped = true
		if v.AutomaticSize == Enum.AutomaticSize.Y then
			v.AutomaticSize = Enum.AutomaticSize.None
		elseif v.AutomaticSize == Enum.AutomaticSize.XY then
			v.AutomaticSize = Enum.AutomaticSize.X
		end
		local XScale = TextBox.Size.X.Scale
		TextBox.Size = UDim2.new(XScale,0,0,TextBox.TextSize*Spacing)
		local NumberOfLines = 1
		local AdjustingSize = false
		local function AdjustTextBoxSize()
			AdjustingSize = true
			TextBox.Size = UDim2.new(XScale,0,0,(TextBox.TextSize*Spacing)*NumberOfLines)
			AdjustingSize = false
		end
		TextBox:GetPropertyChangedSignal("Text"):Connect(function()
			if TextBox.TextFits == false and AdjustingSize == false then
				NumberOfLines += 1
				AdjustTextBoxSize()
			end
		end)
		local OldText = TextBox.Text
		local OriginalName = TextBox.Name
		TextBox.Name = "ScriptRelocatingThisInstance"
		local TextBoxParentClone = TextBox.Parent:clone()
		for i,v in pairs(TextBoxParentClone:GetDescendants()) do
			if v:IsA("Script") or v:IsA("LocalScript") then
				v.Disabled = true
				v:Destroy()
			end
		end
		TextBoxParentClone.Visible = false
		TextBoxParentClone.Name = TextBox.Parent.Name.."(ScriptClone)"
		TextBoxParentClone.Parent = TextBox.Parent.Parent
		local TextBoxClone = TextBoxParentClone:FindFirstChild("ScriptRelocatingThisInstance")
		if not TextBoxClone then error("Could not find clone for textbox.") end
		TextBox.Name = OriginalName
		local TestingSize = false
		TextBox:GetPropertyChangedSignal("Text"):Connect(function()
			TextBoxClone.Text = TextBox.Text
			TextBoxClone.Size = UDim2.new(XScale,0,0,(TextBox.TextSize*Spacing)*NumberOfLines)
			if TextBox.Text:len() < OldText:len() and TestingSize == false  and TextBoxClone.TextFits == true then
				TestingSize = true
				local OldTextCapture = OldText
				local ProperFit = NumberOfLines
				for i = 1, NumberOfLines do
					TextBoxClone.Size = UDim2.new(XScale,0,0,((TextBox.TextSize*Spacing)*(NumberOfLines-i) ) )
					if TextBoxClone.TextFits == false then
						ProperFit = NumberOfLines - (i-1)
						break
					end
					--wait()
				end
				if ProperFit ~= NumberOfLines then
					NumberOfLines = ProperFit
					AdjustTextBoxSize()
				end
				TestingSize = false
			end
			OldText = TextBox.Text
		end)
	end
end
6 Likes

To make TextLabel work with AutomaticCanvasSize you need to set “RichText” property to true.
I dissapointed that it isn’t fixed yet.

7 Likes