We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So far I have been dealing with wrapping text by specifying its size inside 'if' statements, but there surely has to be a more convenient way. I have searched around the internet to no avail. Does anyone have a suggestions on how to wrap text inside a given space?
Answers
Look at text() reference
You can use it with 5 parameters which holds the text in a box
It doesn't seem to work... Am I doing something wrong?
What do you expect that code to do? What does it do instead?
You can control the alignment of the text inside the specified text area with the textAlign() method.
At first I was testing whether it would display the integer 'score' as text. It did not work, then I tried with 'Hello', then creating a rectangle with size width/2 and height/2, in the middle of the screen, then wrap the string inside this rectangle. The string does get displayed, but it obviously does not wrap.
Obviously still does not work.
it works
you didn't have the same last 2 paremeters in text() correct!!!
here it is
This still does not suit my needs though.
What I need is, for example, when I'm displaying an integer as text and I want it to be centered inside a square, it would need a different size and position depending on how many digits it has (10000 would leave the square's bounds while 10 can be pretty big without leaving them). What's the best way to do that?
Well, that's something else than wrap a text...
here is a idea for the text size
see
https://forum.processing.org/two/discussion/20238/scale-text-to-screen-width
you can combine the two approaches I guess:
when the text gets longer, the size gets smaller (function
fittedText
above)but you don't want to get it smaller than let's say
6
points.from that text length onward, we don't decrease the text size anymore but we do line wrap (
text()
with 5 parameters)Chrisir