Font on Button Processing an controlP5

Hi everyone,

I try to set my font on my button, i tried a few thinks like

public ControlFont(processing.core.PFont theFont)

but it doesen’t really work but its my first projekt with processing an controlP5,
I also tried things I know from css and html…

here is my code :

import controlP5.*;

ControlP5 cp5;

int myColor = color(#B7AEAE);

int c1,c2;

float n,n1;

void setup() {
  
 PFont font;
font =  loadFont("CorbelLight-48.vlw");


  size(510, 800);
  cp5 = new ControlP5(this);
    // create a new button with name '9'
  cp5.addButton("9")
     .setValue(9)
     .setPosition(370,60)
     .setSize(100,100);
 
   }


void draw() {
  background(#363936);
  stroke(#6A6664);
  fill(#466E9D);
  
  //      x    y   width
  square(370, 60, 100);
 
     
  square(260, 60, 100);
  square(150, 60, 100);
  square(40, 60, 100);
  
  square(370, 170, 100);
  square(260, 170, 100);
  square(150, 170, 100);
  square(40, 170, 100);
  
  square(370, 280, 100);
  square(260, 280, 100);
  square(150, 280, 100);
  square(40, 280, 100);
  
  square(370, 390, 100);
  square(260, 390, 100);
  square(150, 390, 100);
  square(40, 390, 100);
  
}

Yeah, you need to pass the font to the button. But not in the cp5.addButton("9") section but separately

Sketch

// http://www.sojamo.de/libraries/controlP5/examples/use/ControlP5controlFont/ControlP5controlFont.pde 

import controlP5.*;

ControlP5 cp5;

int myColor = color(#B7AEAE);
int c1, c2;
float n, n1;

void setup() {
  size(510, 800);

  // load / make a new font. ControlFont is a wrapper for processing's PFont
  // with processing 1.1 ControlFont.setSmooth() is not supported anymore.
  // to display a font as smooth or non-smooth, use true/false as 3rd parameter
  // when creating a PFont:

  PFont pfont1;
  // pfont1 = createFont("CorbelLight-48.vlw", 14);
  // pfont1 = createFont("Arial", 20, true); // use true/false for smooth/no-smooth
  // pfont1 = createFont("Alien Encounters", 40, true); // use true/false for smooth/no-smooth
  pfont1 = createFont("Calvin", 40, true); // use true/false for smooth/no-smooth

  ControlFont cfont = new ControlFont(pfont1, 40);

  cp5 = new ControlP5(this);
  // create a new button with name '9' / A 
  cp5.addButton("A")
    .setValue(9)
    .setPosition(370, 60)
    .setSize(100, 100);
  //

  //
  // change the font of the captionlabels 
  // for button created earlier.
  cp5.getController("A")
    .getCaptionLabel()
    .setFont(cfont)
    .toUpperCase(false)
    .setSize(40)
    ;
}

void draw() {
  background(#363936);
  stroke(#6A6664);
  fill(#466E9D);

  //      x    y   width
  square(370, 60, 100);


  square(260, 60, 100);
  square(150, 60, 100);
  square(40, 60, 100);

  square(370, 170, 100);
  square(260, 170, 100);
  square(150, 170, 100);
  square(40, 170, 100);

  square(370, 280, 100);
  square(260, 280, 100);
  square(150, 280, 100);
  square(40, 280, 100);

  square(370, 390, 100);
  square(260, 390, 100);
  square(150, 390, 100);
  square(40, 390, 100);
}

//void square(float x, float y, float size1) {
//  rect(x, y, 
//    size1, size1);
//}
//

1 Like

Thank you Chrisir!

You are the hero of my day !
and thanks alot for the explanations!

1 Like