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.
IndexProgramming Questions & HelpSyntax Questions › Pixel length of a string
Page Index Toggle Pages: 1
Pixel length of a string (Read 724 times)
Pixel length of a string
Mar 2nd, 2007, 5:37am
 
Hi,
I'm using this function to display text on the screen.
text("ABCD",100,100);
I need to know how many pixels the "ABCD" letters would occupy on the screen (width-wise). The height it occupies would obviously be the font height, but what about the width?

I need this badly, coz I'm making a textfield class, and the characters I type in the textfield have to be shown only within the textfield, and should not overshoot the limits.

I've searched, but couldn't find any function which would give the number of pixels occupied by a text.

Please help... Smiley
Re: Pixel length of a string
Reply #1 - Mar 2nd, 2007, 9:27am
 
You're looking for textWidth():

http://processing.org/reference/textWidth_.html
Re: Pixel length of a string
Reply #2 - Mar 2nd, 2007, 11:12am
 
Thank you so much!! Smiley
I'm cursing myself for not finding that function earlier!!

Page Index Toggle Pages: 1