controlp5 icon indicating copy to clipboard operation
controlp5 copied to clipboard

Processing 3 : pixelDensity(2) affecting Textfield appearance

Open melaniehuang opened this issue 9 years ago • 2 comments

All the Textfield input text was disappearing from my Processing 3 sketch.

I found this was being caused by the new Processing 3 function pixelDensity() when set to pixelDensity(2). pixelDensity(1) is fine, as expected.

pixelDensity(2) renders strangely large text at sizes 20+ or completely disappears at sizes 19 and below.

Hope this helps!

See example code below:

import controlP5.*;
ControlP5 cp5;

String textValue = "";

void setup(){
  size(700,400);
  pixelDensity(2);

  cp5 = new ControlP5(this);

  cp5.addTextfield("textValue")
        .setPosition(20,170)
        .setSize(200,40)
        .setFont(createFont("arial",20)); 
}

void draw(){
  background(0);
  fill(255);
  text(textValue, 360,180);
}

melaniehuang avatar Oct 21 '15 11:10 melaniehuang

ok, thanks for reporting. I will have a look. Without digging deeper, I suspect the pixelDensity might not be applied to the PGraphics element which is used to render text for a textfield controller.

sojamo avatar Oct 22 '15 03:10 sojamo

something that might be helpful... if you use PApplet.createGraphics() on an instance of PApplet that already has pixel density == 2, then that will propagate to the created pgraphics. (via PGraphics makeGraphics(...) { pg.setParent(..) }) It looks like you do that when creating the 'buffer', so I think that's all good.

However, one must be careful when using absolute coordinates OR sizes (widths, heights) OR displacements (e.g. distance of point A to point B) with any PGraphics that is2X() == true. (i.e. pixelDensity == 2) Then the specified position, width or height, or displacement will automatically get doubled by the renderer. This is particularly problematic if one assumes a certain size based on a known input or hardcoded value.. e.g. createFont(...,20). It's a size=20 font to the source code's calculations, but the renderer will double it when drawing.

I was trying to patch up the Textfield class by adding if (is2X()) {} blocks in places like draw() and align() but I didn't quite get it right; it turns out I'd need to put in extra time (that I don't have) to really understand the rendering flow. So maybe this comment will be enough to speed up your fix of this

Finally, I would argue this issue should not be tagged "enhancement", but rather a "bug", and a somewhat serious one. As a large majority of people have moved to Processing3 at this point, and a huge user base uses Apple Macbooks ...and almost all Macbooks at this point have Retina displays capable of pixelDensity=2 operation... ===> this makes Textfield and Textarea (*and to a smaller degree, Labels, although this can be worked around), practically unusable for a lot of people

harvv avatar Apr 14 '17 06:04 harvv