Text function wrapping - Hyphens vs Full word line break

Hello! I’m having trouble using the text() function in p5.js.

I understand that when you provide 5 inputs to the function, the last four describe a rectangle in which it will wrap your provided string. However, in some of my projects it wraps the text by hyphenating the words that cross the box, and moving the rest of the word to the next line, and in other projects if a word crosses the box it moves the entire word to the next line.

Ex 1:
The quick brown fox jump-
ed over the lazy dog.

Ex 2:
The quick brown fox
jumped over the lazy dog.

My issue is that I don’t know how to tell the function which of these options I want.
In most instances I’d prefer the second option, but p5.js seems to be deciding at random which option it takes.

Thanks in advance to anyone who can help me with this! :slight_smile:

When your text is always the same you can use \n to make a manual line break

Hi! Welcome to the forum!

are you sure that hyphenation happens with text function and not with DOM? I don’t see it implemented besides the recent addition of textWrap (it will be added in the next release it seems). It would be great if you can provide an example.

1 Like