Topic was automatically imported from the old Question2Answer platform.
Asked By
MarcPhi
Hello is there a way to get the real size of a label, when the text is clipping above the normal bounderies or is there a ways to check if the text clips)?
Hello, I do not understand very well what you want to do, but on the label you can activate the Autowrap option, so that the text is not cut.
Aquiles | 2019-10-29 17:14
hey thats exactly what i did, but i want to know when the text uses autowrap so i can change the text size accordingly
MarcPhi | 2019-10-29 18:05
a slightly crude solution, it would be to see how many characters enter the specific width and then compare with $Label.get_total_character_count() that will return you a number of characters.
You could use the resized() signal, and get the size of the Label with $Label.rect_size. The properties “Clip text” and “Autowrap” have to be off for this to work.
EDIT:
Since you want to have autowrap on, you need to check the size (in pixels) of your longest word:
func check_word_size():
var font = $Label.get_font("font")
var words = $Label.text.split(" ",false)
var longest_word = ""
for i in words:
if font.get_string_size(i).x > font.get_string_size(longest_word).x:
longest_word = i
if font.get_string_size(longest_word).x > $Label.rect_size.x:
# WORD IS BIGGER THAN THE LABEL'S RECTANGLE
pass
the problem with that solution is that i would need to split the text in lines on my own
will resize the Label until the text fits in one line.
You could use a similar method to shrink the font size, but this very easily leads to font size zero if you don’t know how long your String could potentially be.