sojamo / controlp5

A gui library for processing.org
GNU Lesser General Public License v2.1
490 stars 142 forks source link

textlabel can't change background colour. #121

Open RichardDL99 opened 6 years ago

RichardDL99 commented 6 years ago

I want make a Textlabel with choice of background colour. The list of methods includes setColorBackground so I've tried this but it doesn't work for me. (TextField has same method in same place in doc, and it works there.)

/*

import controlP5.*; ControlP5 cp5; Textlabel myTextlabelA;

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)) .setColorBackground(0xff880000); // ?? }

void draw() { background(0); }

Processing 3.3.6 ControlP5 ? files are 24/2/2017

sojamo commented 6 years ago

Hi, this is not ideal and not intuitive but to set the background you need to go the following route and apply changes to the Label class of a Textlabel (also see ControllerStyle class):

import controlP5.*;
ControlP5 cp5;
Textlabel myTextlabelA;

void setup() {
  size(700, 400);
  cp5 = new ControlP5(this);

  // first create a textlabel and position it
  myTextlabelA = cp5.addTextlabel("label")
    .setText("A single ControlP5 textlabel, in yellow.")
    .setPosition(100, 50)
    .setColorValue(0xffffff00)
    .setFont(createFont("Georgia", 20))
    ;

  // next, get the Label class of that Textlabel  
  // and make changes to the background like this
  Label label = myTextlabelA.get();
  label.enableColorBackground().setColorBackground(0xff880000);

  // make changes to the style of the controller
  ControllerStyle style = label.getStyle();
  style.setPadding(10, 10, 10, 10);
}

void draw() {
  background(0);
}
RichardDL99 commented 6 years ago

Thanks. I've tried the code and it works, but as you say not ideal. I wish I knew how to build this code into setColourBackground.