We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware,  Documentation,  Website Suggestions › Suggestion: have text() return pixel width
Page Index Toggle Pages: 1
Suggestion: have text() return pixel width (Read 992 times)
Suggestion: have text() return pixel width
Jun 8th, 2007, 7:33pm
 
Admittedly a subtlety, but it would be great if Processing could have text() return the pixel width of the text it just rendered. I often find myself trying to put some text after other text, but with a different style so it has to be a separate text() call:

THIS IS THE TITLE  and this is the subtitle

requires me to do something like
Code:
textFont( titleFont );
text( title, 100, 100 );
float subTitleOffset = textWidth( title + " " );
textFont( subtitleFont );
text( subTitle, subTitleOffset, 100 );

It would be sweeter if I could simply:
Code:
textFont( titleFont );
float subTitleOffset = text( title + " ", 100, 100 );
textFont( subtitleFont );
text( subTitle, subTitleOffset, 100 );

I'm sure there would be other uses as well.
Re: Suggestion: have text() return pixel width
Reply #1 - Jun 9th, 2007, 1:47am
 
It would be sweeter if you can use debug-like text to draw text. Like wit hLuaPlayer for PSP, screen:print() would just let you put in the location and text, no calling up fonts or making a new PFont variable. That would be nice for debugging.
Re: Suggestion: have text() return pixel width
Reply #2 - Jun 10th, 2007, 2:40pm
 
at least for now, if you use the text() command with no x and y coordinates, it will draw the text immediately after the last text drawn.

but i'm not sure if that api feature will stay in. having text() return the width sounds like a better option, rather than keeping track of internal state (though this doesn't keep track of the y coordinate of the text...)
Re: Suggestion: have text() return pixel width
Reply #3 - Jun 12th, 2007, 12:18am
 
Wow, that's a useful feature. If you do go with the return-value solution, I don't think the Y-axis value is as necessary because in general I already know it from having used it in the first text() call.
Page Index Toggle Pages: 1