2 Column Label/RichTextLabel

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

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?

:bust_in_silhouette: Reply From: Ertain

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.

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!

andersmmg | 2021-04-08 00:44

:bust_in_silhouette: Reply From: trisolaran

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.get_string_size(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.