Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (44 sloc) 1.06 KB
class TextField extends View {
String value = "";
int pos;
color fgColor = 255;
final static int MARGIN = 3;
Action<TextField> action = null;
TextField(float x_, float y_, float w_, float h_)
{
super(x_,y_,w_,h_);
}
void setAction(Action<TextField> action)
{
this.action = action;
}
void drawContent(float lx, float ly)
{
strokeWeight(1);
stroke(fgColor);
noFill();
rect(0, 0, w, h);
fill(fgColor);
textAlign(LEFT, CENTER);
text(value, MARGIN, h/2);
if (focusView == this && ((millis() / 500) % 2 == 0)) {
float tw = textWidth(value);
line(MARGIN + tw, MARGIN, MARGIN + tw, h-MARGIN);
}
}
boolean contentClicked(float lx, float ly)
{
focusView = this;
return true;
}
void keyTyped()
{
if (key == CODED) println(keyCode);
else {
if (key == ENTER) return;
if (key == BACKSPACE && value.length() > 0) value = value.substring(0, value.length()-1);
else value = value + key;
if (action != null) action.respond(this);
}
}
}
Something went wrong with that request. Please try again.