Get height/line count of label [SOLVED]

When creating labels I have the ‘Line Break’ feature enabled but I’m trying to stack labels vertically similar to a chat/message feed with messages varying in length. I struggle with not knowing how many lines the label spans or more specifically how much vertical space the text label takes up.
Is there any way to get a line count of a label element somehow? Or possibly the actual height of the label box. I couldn’t find such a thing when I searched the documents but it seems like if there’s a way to enable text wrapping at a certain width there should be some way to find how many times it wraps. (maybe?)
I’m personally hoping for something like go.get('#label', 'linecount') or something.

First time posting so please allow some tolerance if the question is somewhat nooby or already asked. I searched beforehand but couldn’t find anything.

Hi @Numerousness ! You can use resource.get_text_metrics() to calculate the bounding box of a text using a specific font, max width etc:

2 Likes

Perfect! Thanks for the quick response too. The linked documentation will work just fine for my use case. Pretty much exactly what I was looking for. I just wasn’t looking under the ‘resource’ section for documentation.

For completeness, here’s the sample code from the documentation that allowed me to get the height of the label box:

    local font = go.get("#label", "font")
    local metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog")
    print(metrics.height)
5 Likes