ControlP5 - font/color & linebreak() usage

edited March 2014 in Library Questions

Hi, I have just found this library, but do not know how to implement linebreak() or font/color/size changes for Textlabel. When I try to change the font it doesn't work, and I don't know how to use linebreak and can't find any information - (Beginner) Cheers!

Tagged:

Answers

  • edited March 2014

    Here is an example. You can line break with \n. setColorValue() and setFont along with the size.

    import controlP5.*;
    
    ControlP5 cp5;
    
    Textlabel myTextlabelA;
    Textlabel myTextlabelB;
    
    void setup() {
      size(700,400);
      cp5 = new ControlP5(this);
    
      myTextlabelA = cp5.addTextlabel("label")
                        .setText("A single ControlP5 textlabel, in yellow.")
                        .setPosition(100,50)
                        .setColorValue(0xffffff00)
                        .setFont(createFont("Georgia", 20))
                        ;
    
      myTextlabelB = new Textlabel(cp5,"Another textlabel, \nnot created through ControlP5 needs to be rendered separately by calling Textlabel.draw(PApplet).",100,100,400,200);
    
    }
    
    
    
    void draw() {
      background(0);
      myTextlabelB.draw(this); 
    }
    

    Check the documentation for the textlabel here, you have all the functions that you can implement. sojamo.de/libraries/controlP5/

  • edited March 2014

    Hi thanks so much, I did find this, but when I tried to change the textLabel (the text beside a checkbox for example) it would not change. For example in this segment, I cannot find a way to change the text after '.addItem'. I have tried to import font etc and it seems to work everywhere but here.

     cp5 = new ControlP5(this);
      checkbox = cp5.addCheckBox("checkBox")
        .setPosition(100, 200)
          .setColorForeground(color(120))
            .setColorActive(color(#0CA4E8))
              .setColorLabel(color(0))
                .setSize(40, 40)
                  .setItemsPerRow(1)
                    .setSpacingColumn(30)
                      .setSpacingRow(20)
    
      .addItem("Interaction: 2 = Normal, 1 = Some, 0 = Hides", 0);
    
  • What do you need to change specifically? Font/color or the text itself?

  • The font - colour and size. Still going through all the libraries... I have found some old stuff from 2009 but it does't work any more -

  • edited March 2014 Answer ✓

    They do work. setColorLabel(color(0)) gives you the color of the label, and you set it to 0 meaning black. color() can take 3 parameters inside color(red, green, blue) thus giving you the spectrum of colors. For the font type and size use cp5.setFont(createFont("dotum", 22)). You can also make groups of elements to get a different font for each one.

  • edited March 2014

    Ok thanks, will give it another go, I think maybe I am over thinking this though and just need to do some radio buttons, that may make it easier? Basically I need; - user input (buttons 0-2 x6 rows), and an addition calculation for each number input. Is there a specific kind of button that may work better for that? I initially began with the ControlP5 because it had 'checkboxes'.

    I did figure out the font thing, but the smoothing doesn't work. I just ended up using text() instead.

    Cheers;-)

  • How did you figure it out with the font?

    Thanks for your help

Sign In or Register to comment.