+2 votes

I've searched all over the internet and through the docs and yet still can't seem to find a way to make the label fit within a certain area. I'm adding an arrays of ints as a string to the label, and they continue expanding without making a new line, causing it to cut off the screen. Is there any way around this?

Godot version 3.4.2
in Engine by (105 points)

3 Answers

0 votes

You can use \n to create a new line for instance

print("Hello \n World") 

will print as

Hello
World

by (3,321 points)
0 votes

I separate your question into two small question to answer.

Q1. Find a way to make the label fit within a certain area.
This problem you can use "ScrollContainer" as Label's parent to fix it.
I mean this:
ScrollContainer(parent node)
-Label(child node)

Q2. You want Label automatically make a new line when got longer text.
To fix this problem you only need to check the property "autowrap" is true in Label Node's Inspector.

Then You got this:
imgResult Image Link

Hope this help.

by (526 points)
edited by
0 votes

I'll be the third person to have a crack at this. :) If you've got a solid string of numbers I suspect autowrap might not work. I guess you could just take the modulus if all else fails:

var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
var line_length = 7
var string = ""

for item in array.size():
    if item and not item % line_length:
        string += "\n"
    string += str(array[item])

printt(string)

Outputs:

0123456
7890123
4567890
1234567
89

Or, you could loop the string rather than the array. Anyway, you get the idea hopefully.

by (2,156 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.