Get text size from a RichTextLabel control (in GDScript)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By radubolovan
:warning: Old Version Published before Godot 3 was released.

Hello,

I’m trying to make a dynamical resizing height dialog (the width will always be fixed). My control (dialog) has 1 background texture, a title (fixed maximum width), a text (fixed maximum width) and some buttons (OK, Cancel, Yes, No, etc).

Title type: Label
Text type: RichTextLabel

What I want to do:

  1. Resize the background texture (the height) every time I set the title, the text and set the buttons:
    var title_height = get_node("Title").get_line_height() var text_height = ? (I need this information) var total_height = top_margin + bottom_margin + dist_between_title_ and_text + dist_between_text_and_buttons + title_height + text_height var texture_height = total_height.

  2. Rearrange the buttons’ positions by the size of the total height:
    var buttons_pos_y = top_margin + dist_between_title_ and_text + dist_between_text_and_buttons + title_height + text_height

Please see in the above code what I need to find out (there’s a question mark).
I looked in RichTextLabel class and I couldn’t find nothing like get_text_size() or get_text_width() & get_text_height()

P.S. Both (title and text) controls have Dynamic Font (.ttf) set.

Cheers,
Radu

Hi!

I know this is like a necrobump, but did you ever solve the problem?

I’m looking for a way to get_text_width() too but so far haven’t found a solution.

mjtorn | 2018-04-09 10:53

:bust_in_silhouette: Reply From: jackmakesthings

I’m dealing with a similar issue in my own project! You can use get_size().y on the RichTextLabel to get its height - you may need to set the Vertical size flags to “Expand, Fill”, that’s generally what I’m doing. I’ll see if I can put together a demo version from what I’ve done, but start with that.