controlP5 RadioButton question

Hello!

In I project using cp5, I want to display a list of toggles, each of which has a corresponding group of controllers.

Here is the relevant code:

cp5.addRadioButton("shape picker")
    .addItem("line", 1)
    .addItem("free draw", 2)
    .addItem("polygon", 3)
    .addItem("curve", 4)
    .addItem("free curve", 5)
    .addItem("ellipse", 6)
    ; 

for (Toggle t : cp5.getController("shape picker").getItems()){
    cp5.addGroup(t.getName()+" settings")
    ;
}

Basically, I want a settings menu for each mode described in the radio button initialization.

The error I run into is “the function getItems() does not exist”. And surely, when I look at the RadioButton Javadoc, both getItem(int) and getItems() are methods for the Toggle class. That is to say, I cannot find a method in the RadioButton class that returns the toggles that comprise it. Is there a way to access these toggles that I am missing?

1 Like

yes, just stay more close to the example!
and please post running code ( besides your problematic command )

also i not understand why you want do a addGroup,
as your RadioButton with addItem already is like a Group
( meaning like it functions already as select one of n )

also what should the

+" settings"

do?

but you can add the whole
RadioButton(s) to a group if you want.

i play this:

import controlP5.*;

ControlP5 cp5;
RadioButton r1;
Group g1;

void setup() {
  size(700, 400);

  cp5 = new ControlP5(this);
  r1 = cp5.addRadioButton("shape picker")
    .setPosition(100, 100)
    .setSize(20, 20)
    .addItem("line", 1)
    .addItem("free draw", 2)
    .addItem("polygon", 3)
    .addItem("curve", 4)
    .addItem("free curve", 5)
    .addItem("ellipse", 6)
    .addItem("triangle", 7)
    ; 

  g1 = cp5.addGroup("mysettings");
  g1.add(r1);

  for (Toggle t : r1.getItems()) {
    println(t.getName());
    //cp5.addGroup(t.getName()+" settings");  // but you did a addItem, why try a addGroup ? and add text " settings" ??
  }
}

void draw() {
  background(200, 200, 0);
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isFrom(r1)) {
    print("event from "+theEvent.getName()+"\t");
    for (int i=0; i<theEvent.getGroup().getArrayValue().length; i++)   print(int(theEvent.getGroup().getArrayValue()[i]));
    println("\t "+theEvent.getValue());
  }
}

1 Like