Topic was automatically imported from the old Question2Answer platform.
Asked By
pcole
Old Version
Published before Godot 3 was released.
I’m trying to determine how I can get my label to update its size when a smaller string has been added to it. For example, I have a label that states “Sample Label” and its size comes out to (85, 14).
However, when I call the set_text method with a value of “A”, the label still reports a size of (85, 14). Is there a way to report the correct size with just the one character present?
GODOT 3.0:
in my case i needed to manually adapt the height of an outer container that contained a background NinePatchRect, so with just waiting for the _process I could catch the size change correctly, but then I had to change the size of the NinePatch, which took another drawcycle to be done and would not be shown immediately.
What DOES work actually right away is getting the number of lines after setting a new text for your label!
So in my specific case (ONLY vertical growth, now width change) I could just use get_line_height() and multiply it by label.get_line_count() RIGHT AFTER I set the text with label.text
p.s.: actually, in my case the get_line_height() did not give me the correct value, it reported the line to be 3 pixels lower than it actualy was, not sure if that has to do with some setting i used for my label, so i ended up using fixed line_height values in my script and adding a padding for good measure.