Using Cp5, I'm attempting to create a textfield. I want the user to only be able to edit the textfield after clicking a button. The user is unable to edit the textfield if the button is not pressed. Does Textfield have a method that can assist me with this function? I am asking because I didn't find any documentation for the methods in the library.
CodePudding user response:
setLock() should do what you want to do:
import controlP5.*;
ControlP5 cp5;
String textValue = "";
public void lock() {
cp5.get(Textfield.class, "textField").setLock(true);
}
public void unlock() {
cp5.get(Textfield.class, "textField").setLock(false);
}
void setup() {
size(700, 400);
background(0);
fill(255);
PFont font = createFont("arial", 20);
cp5 = new ControlP5(this);
cp5.addTextfield("textField")
.setPosition(60, 100)
.setSize(150, 30)
.setFont(createFont("arial", 18))
.setAutoClear(false)
.setLock(false);
;
cp5.addBang("lock")
.setPosition(240, 100)
.setSize(60, 30)
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;
cp5.addBang("unlock")
.setPosition(330, 100)
.setSize(60, 30)
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;
textFont(font);
}
void draw() {
}