ControlP5: RadioButtons - how to style each button individually?

edited April 2014 in Library Questions

I can style the whole set of RadioButtons, but some text labels are longer than others, so it ends up looking not-so-great. Is there a way to style each button individually? For loops seem to mess up the RadioButton code, ends up getting errors saying "name of RadioButton"/"name of Item" already exists.

Here's the code I'm currently using:

import controlP5.*;
ControlP5 cp5Parts;

setup() {
size(1400, 800, P3D);
cp5Parts = new ControlP5(this);

  ControlFont cf18 = new ControlFont(createFont("Arial",18));
  cp5Parts.setControlFont(cf18);
  cp5Parts.setColorForeground(color(220));
  cp5Parts.setColorBackground(color(205));
  cp5Parts.setColorLabel(linkColor);
  cp5Parts.setColorActive(color(230)); 

Parts = cp5Parts.addRadioButton("PartsButton")
         .setPosition(100, 107)
         .setSize(150, 20)
         .setItemsPerRow(9)
         .setSpacingColumn(0)
         .addItem("Ovary",1)
         .addItem("Head[F]",2)
         .addItem("Integument[F]",3)
         .addItem("Fat Body[F]",4)
         .addItem("Midgut[F]",5)
         .addItem("Hemocyte[F]",6)
         .addItem("Malpighian[F]",7)
         .addItem("PSG[F]", 8)
         .addItem("AMSG[F]",9)
         .addItem("Testis",10)
         .addItem("Head[M]",11)
         .addItem("Integument[M]",12)
         .addItem("Fat Body[M]",13)
         .addItem("Midgut[M]",14)
         .addItem("Hemocyte[M]",15)
         .addItem("Malpighian[M]",16)
         .addItem("PSG[M]",17)
         ;

  for(Toggle tt:Parts.getItems()) {
       tt.captionLabel().style().moveMargin(0, 0, 0, -150);
       tt.captionLabel().style().movePadding(0, 0, 0, 0);
     }
}

void draw() {

// Other stuff 

}

Thanks.

Answers

  • Hi, there is no out of the box solution to do what you are looking for, maybe centering the label and adding some spacing helps?

  • edited April 2014

    @sojamo How would I center the label?

    ... Never mind, I guess putting spaces in the label names. Not exactly ideal, but it will have to do I guess.

Sign In or Register to comment.