Avoid trailing words in line break text nodes

#1

Could this be achieved programmatically somehow? Is there a way to get number of words per line?

0 Likes

#2

You want to break the text earlier than the width of the text field? Why? If you use a text node or label and have enabled line breaks there is unfortunately no API to get the number of words per line.

You would have to use RichText to achieve that kind of functionality.

0 Likes

#3

Because the client says so. :slight_smile: I suppose it’s quite a natural way of displaying text blocks, to make it more readable.

I had a look at the extension. Looks awesome! It relies on the text itself for all formatting, right, so it couldn’t be used to get number of words per line?

0 Likes

#4

You give it a text and some configuration data (font, width etc) and it gives back nodes and a list of words.

Now that I think of it it doesn’t automatically solve your problem… I think you’d need to create your own parser and split the text into words, measure each word using gui.get_text_metrics() and manually insert a linebreak (\n) where it is needed.

1 Like

#5

is the goal to avoid widows specifically? depending on how many there are case-by-case couldn’t you just insert a few /n new lines or is it something else.

In a case I have, I just decided to set a limit I knew fit various fonts and spaces I’m using, and then use a lookup table with string.len functions to build some small intelligence into my text display fields.

2 Likes

#6

These are good options, thanks! Yes, in this case it’s widows (that’s the word!) only.

1 Like