Cp5 TextField bug

Hi,
Something weird with TextField controller from cp5:
In a project, I have to manage the visibility of an ArrayList of Textfield controllers, according different parameters. So the best way I found to do it is in my draw() loop, when a parameter has changed, to set first all of them not visibles and then to re-set visible the ones I want. Works fine, but…
The only thing is then, I can’t edit the text in the Textfields anymore!! I can click on it, get the focus, but not more.
And If I comment the line making them not visible, then I can correctly edit the texts…
So the questions: Is it just a cp5 bug? Or Am I doing something wrong? What could make a Textfield not editable?
I’m sorry, I can’t post any code. It’s a part of a big project, with parts everywhere in different tabs. I tried to reproduce the problem in a simplified version, but I’ve not been able…
Any ideas?

I quickly tried to modify an example code, and I couldn’t reproduce your problem. Here hiding and unhiding works fine, text is still editable after that. So I guess you might need to work out how much of your code is needed to reproduce the effect?

My working code:

import controlP5.*;

ControlP5 cp5;
Textfield test;

String textValue = "";

void setup() {
  size(700,400);
  
  PFont font = createFont("arial",20);
  
  cp5 = new ControlP5(this);
  
  test = cp5.addTextfield("input")
     .setPosition(20,100)
     .setSize(200,40)
     .setFont(font)
     .setFocus(true)
     .setColor(color(255,0,0))
     ;
     
  textFont(font);
}

void draw() {
  background(0);
  fill(255);
  text(cp5.get(Textfield.class,"input").getText(), 360,130);
  text(textValue, 360,180);
}


void keyPressed(){
  if (key == 'a'){
    test.setVisible(false);
  } else {
    test.setVisible(true);
  }
}

Hi,
Thanks for your answer. Yes, it’s not easy to reproduce. Really tricky…
Looks like it’s linked to the fact that I hide and unhide in the same draw loop.
I maybe found what’s going on. I have been able to reproduce something similar:

import controlP5.*;

ControlP5 cp5;
Textfield test;

String textValue = "";
boolean redraw=true;

void setup() {
  size(700,400);
  
  PFont font = createFont("arial",20);
  
  cp5 = new ControlP5(this);
  
  test = cp5.addTextfield("input")
     .setPosition(20,100)
     .setSize(200,40)
     .setFont(font)
     .setColor(color(255,0,0))
     ;
     
  textFont(font);
}

void draw() {
  if (redraw){
    background(0);
    fill(255);
    test.setVisible(false);
    test.setVisible(true);
    text(cp5.get(Textfield.class,"input").getText(), 360,130);
    text(textValue, 360,180);
    redraw=false;
  }
}


void keyPressed(){
  if (key == 'a'){
    redraw=true;
  } 
}

If you click in the textfield, then press ‘a’, after that, you can’t write anything else even if the focus is still on it. You have to click again in the textfield to do be able to write again.
And you don’t have this problem if you comment the line “test.setVisible(false);”
Must be something like that. It means it keeps the focus but loses something I would have to reactivate after. But which parameter?..

Got it!
By adding test.setFocus(true); after test.setVisible(true); the problem disappears.
So it seems to keep the focus (test.isFocus() return true) but in fact not. So it requires to be set back on after that.
Sorted!
Thanks for your help!

working code:

import controlP5.*;

ControlP5 cp5;
Textfield test;

String textValue = "";
boolean redraw=true;

void setup() {
  size(700,400);
  
  PFont font = createFont("arial",20);
  
  cp5 = new ControlP5(this);
  
  test = cp5.addTextfield("input")
     .setPosition(20,100)
     .setSize(200,40)
     .setFont(font)
     .setColor(color(255,0,0))
     ;
     
  textFont(font);
}

void draw() {
  if (redraw){
    background(0);
    fill(255);
    test.setVisible(false);
    test.setVisible(true);
    println(test.isFocus());
    if (test.isFocus()){test.setFocus(true);}
    text(cp5.get(Textfield.class,"input").getText(), 360,130);
    text(textValue, 360,180);
    redraw=false;
  }
}


void keyPressed(){
  if (key == 'a'){
    redraw=true;
  } 
}