text new line?

Is there a way to make text work with newlines? For example if I do text(“hello/world”,300,30) to make it show the two words in separate lines?

The alternative is for me to emulate the newline myself but wanted to know if there’s a way to make it just work

Yes, it’s a bit unintuitive but you need to set textWrapWidth() to something — setting a textWrapWidth() will enable multi-line text. Which will then allow your text drawing to respect newlines. (You can set it to any value — set it to some large value if you want to handle newlines all on your own. Setting it smaller will automatically wrap text as well as respect newlines.)

Awesome! I was just starting to write code to handle this and realizing how complicated the logic for deciding whether your word needs to wrap to the next line actually is. I’ll stop bugging about the fact that codea doesn’t color wrapped lines correctly now :slight_smile:

can you think of any way to figure out the position, in pixels, of the last char of the text when using textWrapWidth?

I’m writing a multi line textbox and want to know the position where I should place the cursor. I though I’d find the pixel position of the last char by removing one char at a time from the end of the string and waiting until the text height got smaller (which I can find with textSize). This would give me the last line of the text, and I could figure out the x-coordinate of the cursor from that.

However this fails because sometimes removing 1 character from the end of the line causes a whole word to move up one line. My code thinks that only 1 char is in the last line, when in reality it’s a whole word.

never mind, stupid question. I know that it will never be a single char in the last line, it will be a whole word. So the x-coordinate of the cursor is determined by the length of that word.