artvl21 / controlp5

Automatically exported from code.google.com/p/controlp5
0 stars 0 forks source link

ListBoxItem color problem if the box does not need scroll #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
/**
 * ControlP5 ListBox
 * listBox operates the same way as a scrollList, but
 * is optimized for many items (1000+). using a listBox
 * over a scrollList is recommended
 * by andreas schlegel, 2009
 */

import controlP5.*;

ControlP5 controlP5;

ListBox l;
ListBoxItem li;
int cnt = 0;
void setup() {
  size(400,400);
  frameRate(30);
  controlP5 = new ControlP5(this);
  l = controlP5.addListBox("myList",100,100,200,10);
  l.setItemHeight(15);
  l.setBarHeight(15);

  l.captionLabel().toUpperCase(true);
  l.captionLabel().set("something else");
  l.captionLabel().style().marginTop = 3;
  l.valueLabel().style().marginTop = 3; // the +/- sign
    l.setColorBackground(color(255,128));
  l.setColorActive(color(0,0,255,128));

  l.setHeight(120);
  l.setWidth(120);
  //l.setBackgroundColor(color(100,0,0));
  for(int i=0;i<80;i++) {
    li = l.addItem("item "+i,i);
    li.setColorBackground(color(random(128,255),0,0,128));
  }

l = controlP5.addListBox("myList2",250,100,0,10);
  l.setItemHeight(15);
  l.setBarHeight(15);

  l.captionLabel().toUpperCase(true);
  l.captionLabel().set("something else");
  l.captionLabel().style().marginTop = 3;
  l.valueLabel().style().marginTop = 3; // the +/- sign
    l.setColorBackground(color(255,128));
  l.setColorActive(color(0,0,255,128));

  l.setHeight(120);
  l.setWidth(120);
  //l.setBackgroundColor(color(100,0,0));
  for(int i=0;i<5;i++) {
    li = l.addItem("item "+i,i);
    li.setColorBackground(color(random(128,255),0,0,128));
  }

}

void keyPressed() {
  if(key=='1') {
    // set the height of a listBox should alwyays be a multiple of itemHeight
    l.setHeight(210); 
  } 
  else if(key=='2') {
    // set the height of a listBox should alwyays be a multiple of itemHeight
    l.setHeight(120);
  }
  else if(key=='i') {
    // set the height of a listBoxItem, should alwyays be a fraction of the listBox
    l.setItemHeight(30); 
  } 
  else if(key=='u') {
    // set the height of a listBoxItem, should alwyays be a fraction of the listBox
    l.setItemHeight(10);
    l.setBackgroundColor(color(100,0,0));
  } 
  else if(key=='a') {
    int n = (int)(random(100000));
    l.addItem("item "+n, n);
  } 
  else if(key=='d') {
    l.removeItem("item "+cnt);
    cnt++;
  }
}

void controlEvent(ControlEvent theEvent) {
  // ListBox is if type ControlGroup.
  // 1 controlEvent will be executed, where the event
  // originates from a ControlGroup. therefore
  // you need to check the Event with
  // if (theEvent.isGroup())
  // to avoid an error message from controlP5.

  if (theEvent.isGroup()) {
    // an event from a group e.g. scrollList
    println(theEvent.group().value()+" from "+theEvent.group());
  }
}

void draw() {
  background(128);
  // scroll the scroll List according to the mouseX position
  // when holding down SPACE.
  if(keyPressed && key==' ') {
    //l.scroll(mouseX/((float)width)); // scroll taks values between 0 and 1
  }
  if(keyPressed && key==' ') {
    l.setWidth(mouseX);
  }
}

What is the expected output? What do you see instead?
The last item on the right hand list should be a random red, not gray.

What version of the product are you using? On what operating system?
0.5.4

Please provide any additional information below.

Original issue reported on code.google.com by jeffgem...@gmail.com on 12 Nov 2010 at 3:40

GoogleCodeExporter commented 8 years ago
Temp Work around... You can add an additional unnecessary ListBoxItem and then 
remove it.

Original comment by jeffgem...@gmail.com on 12 Nov 2010 at 4:05

GoogleCodeExporter commented 8 years ago

Original comment by soj...@gmail.com on 13 Nov 2010 at 5:25

GoogleCodeExporter commented 8 years ago

Original comment by soj...@gmail.com on 18 Jan 2012 at 4:00