controlp5 icon indicating copy to clipboard operation
controlp5 copied to clipboard

textlabel can't change background colour.

Open RichardDL99 opened this issue 7 years ago • 2 comments

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.)

/*

  • the Textfield library example
  • remove TextFieldB
  • add setColorBackground */

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

RichardDL99 avatar Apr 07 '18 20:04 RichardDL99

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);
}

sojamo avatar Sep 22 '18 05:09 sojamo

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.

RichardDL99 avatar Oct 08 '18 21:10 RichardDL99