Getting the size in pixels of a RichTextLabel.text

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Darenn Keller

Hey guys!

I’m trying to adjust a label.rect_size.x (I’m making a dialog box) relative to the size of the a text inside a it. More precisely, I want the rect_size.x to be the minimum needed size to display the text. I’m using this code :

label.rect_size.x = label.get_font("mono_font").get_string_size(label.text).x 

But the get_string_size() returns a pretty small number and the text does not if in the label (letters are missing). Is the size returned in pixel? Maybe I’m not actually getting the good font? (I have a custom mono_font on my RichTextLabel, I did not find any other way to get the font from my label).

Thanks!

:bust_in_silhouette: Reply From: Darenn Keller

Ok, seems like I used the wrong font :wink: With “normal_font” it is working as intended.

I was also making a dialogue box and your code helped me out. Thank you so much!

FrazzleTime | 2021-01-13 20:09