Question about ControlP5 library

edited March 2016 in Library Questions

Hello, I have questions about the ControlP5 library. Yesterday, I've found this library with a scrollable list example:

import controlP5.*;

import java.util.*;

String[] listItems = new String[5];

ControlP5 cp5;

void setup() {

  size(400, 400);

  surface.setResizable(true);

  listItems[0] = "5130";

  listItems[1] = "5131";

  listItems[2] = "5150";

  listItems[3] = "5170";

  listItems[4] = "9591";

  cp5 = new ControlP5(this);

  List l = Arrays.asList(listItems);

  /* add a ScrollableList, by default it behaves like a DropdownList */

  cp5.addScrollableList("dropdown")

     .setPosition(10, 10)

     .setSize(width-20, height-20)

     .setBarHeight(50)

     .setItemHeight(20)

     .addItems(l)

     .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST

;    

}

void draw() {

  background(240);

}

void dropdown(int n) {

  CColor c = new CColor();

  c.setBackground(color(255,0,0));

  cp5.get(ScrollableList.class, "dropdown").getItem(n).put("color", c);

}

(I've removed some code from the example which was un-necessary for me) Now, I have this questions:

  1. How can I change the cp5.setSize in my loop? As you can see, the sketch size is resizable, but if I change the size of the program, the list size won't change.
  2. How can you set the colors of the list text? I have a very light background, so I need black text in my list. Is this possible?
  3. Is it possible to let the user also unselect items? In this example code, there is no option.

Thanks in advance, Daantje

Answers

  • edited April 2016

    No one knows?

  • Answer ✓

    hi.

    1. use setSize inside draw cp5.get(Controller.class, "dropdown").setSize(width-20, height-20);

    2. use the setColor options when you create the ScrollableList

      .setColorBackground(color(200))
      .setColorActive(color(240))
      .setColorForeground(color(220))
      .setColorValueLabel(color(20))
      .setColorCaptionLabel(color(20))
      
    3. you can file an issue at github.com/sojamo/controlp5/issues as an enhancement

  • Hey, i got a COMport list. Like this. String[] portNames = SerialPortList.getPortNames(); List Ports = Arrays.asList(portNames); sbCOM = cp5.addScrollableList("ComList");

    How can i "Close Port" added at the end of the ArrayList?. Regards Willi

  • edited April 2016

    I have resolve himself. `
    String[] listItems = new String[Serial.list().length+1];

    for (int i = 0; i < Serial.list().length; i++) { printArray(Serial.list());
    listItems[i] = Serial.list()[i]; println(listItems[i] + " "+i); }

    listItems[Serial.list().length] = "Close Port"; `

Sign In or Register to comment.