I want to make it so when my text reaches the limit of the textbox, it becomes scrollable and creates more space for the cutoff text. When You type and it reaches the end of the textbox, it gets cutoff as shown here:
I’ve tried doing it myself and looking on the devforum and I’m still not quite sure of the most efficient way of going about this. My only way I can think of is either checking when textfits = false or by using textbounds.
You’re absolutely on the right track with TextFits and TextBounds. I’ve programmed solutions to similar problems using both in the past. I’d say the right choice for you depends on the context behind how the TextBox will be used. You can use a repeat loop beginning at 1*[Your Line Height] to define the YOffset of the TextBox, then increasing the 1 to 2, 3 an so on until TextFits == true. Alternatively, whenever the text is changed, you can set the TextWrapped property of the TextBox to false, forcing all the text to appear on a single line. This will update the TextBounds property which you can then simply divide the x component by the width (AbsoluteSize.X) of your TextBox to get how many lines will be required to fit all the text. In both cases I’d recommend adding one to a few extra lines just to make sure that the text is not clipped at the bottom. Also, you may have to run a few tests, I have not checked on this in a while but I remember running into an issue where the TextBounds property is not immediately accurate after setting the Text of a TextBox (which would throw off your calculations). Hope this helps!
I understand and have a basic script that can do this now. My only problem is I can’t scroll on the scrollframe because there’s a textbox on top. How should I fix this?
textArea:GetPropertyChangedSignal("TextFits"):Connect(function()
while textArea.TextFits == false do
scrollFrame.CanvasSize = UDim2.new(0, 0, 1, scrollFrame.CanvasSize.Y.Offset + 16)
scrollFrame.CanvasPosition = Vector2.new(0, scrollFrame.CanvasPosition.Y + 16)
end
end)
This so far increases the canvas size and makes the canvas position go to the bottom. If the user deleted their text how would I make it go back to a smaller size?