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 & HelpPrograms › more than one line with selfmade text editor
Page Index Toggle Pages: 1
more than one line with selfmade text editor (Read 880 times)
more than one line with selfmade text editor
Oct 9th, 2009, 6:33am
 
hi there !
In the processing handbook is an example for an
extremely minimal text editor, that can only insert and remove characters from a single line.
I want to have one with more than one line. So I tried a bit around
and endet with
if (key==RETURN){}
in the last line, which works,
but the first thing is:
i don´t know why it works
(because the if clause is empty here)
and second:
there has to be a cleaner more complicatet solution.
thanks for your help!



PFont font;
String letters = " ";

void setup() {
 size (600,800);
 font = loadFont ("Eureka-24.vlw");
 textFont(font);
 stroke(255);
 fill(0);
}

void draw() {
background(204);
float cursorPosition = textWidth (letters);
line(cursorPosition,0,cursorPosition,100);
text(letters,0,50);
}

void keyPressed() {

 if (key == BACKSPACE) {
 if(letters.length()>0) {
 letters = letters.substring(0,letters.length()-1);
 }
 }else if (textWidth(letters+key) < width) {
    letters = letters+key;
 
} if (key==RETURN){}
}
Re: more than one line with selfmade text editor
Reply #1 - Oct 9th, 2009, 7:24am
 
Actually, it works without adding this line...
It works because Return will add a '\n' character and text() call respects this special char. Note if you press Shift, you will also have a strange char, you should filter them out (see CODED).
Re: more than one line with selfmade text editor
Reply #2 - Oct 14th, 2009, 10:28am
 
thanks
Page Index Toggle Pages: 1