0 votes

I want to have some text automatically set to fit in 2 columns for a book. I don't think there's a way in the Label itself to do this, how should I go about wrapping the end to the second column?

Godot version 3.2.3
in Engine by (654 points)

2 Answers

0 votes
Best answer

I suggest trying this: take a MarginContainer and have it fill your scene (maybe give it a rectangular shape). Assign an HBoxContainer as the MarginContainer node's child and set its size property to fill the MarginContainer vertically and horizontally. Then assign two Label nodes as the children of the HBoxContainer. Set those nodes to also fill the vertical and horizontal spaces. After that, add in the text to the Label nodes and you'll have the look you want.

by (3,162 points)
selected by

That does get the look I was hoping for, I'll just need to figure out how to split a string into the labels automatically. Thanks!

0 votes

i have done something similar with a nested vbox/hbox layout, similar to what is described in the first answer. the main problem is to get the right amount of labels into the boxes: first split the text string with words = string.split(" "), which gives an array of all the word in the text. then iterate over the words-array, count chars of any word, put a label with the word in the hbox until a limit is reached, there is the linefeed and begin a new vbox. this doesnt look good, then do some fontmetrics font.getstringsize(wordlist[i]).x, count the sizes of the words do the same label stuff as above until the a limit is reached, there is the linefeed. if it still doesnt look good, then two end-limits and some calculations can make it smooth. the positive side: you can put other objects into the vbox/hbox-layout between the labels(=words). this is not possible in a richtextlabel.

by (69 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.