Export to GitHub

controlp5 - issue #7

listBox scrollbar gets messed up if define the height < 10 during creation


Posted on Nov 12, 2010 by Swift Hippo

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; int cnt = 0; void setup() { size(400,400); frameRate(30); controlP5 = new ControlP5(this); l = controlP5.addListBox("myList",100,100,0,0); //Setting the height < 10 creates a scrollbar issue. 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.setBackgroundColor(color(100,0,0)); for(int i=0;i<80;i++) { l.addItem("item "+i,i); } l.setColorBackground(color(255,128)); l.setColorActive(color(0,0,255,128)); l.setHeight(120); //Setting the height later does not fix the issue l.setWidth(120);

}

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? Normal scrollbar

What version of the product are you using? On what operating system? 0.5.4, Max OSX 10.6.5

Please provide any additional information below. Setting the height to 10 during creation is a work around.

Comment #1

Posted on Nov 13, 2010 by Happy Rhino

Why would you set the width and height to 0 or smaller 10? the height of a listbox should at least be equal or bigger than the itemheight with a minimum value of 10. if the listbox should be made invisible with above technique, could setVisible(false) do the job? or would collapsing the listbox help (use close() )?

Comment #2

Posted on Nov 13, 2010 by Swift Hippo

I calculate the height and width later in the program based on some other variables. So what I was doing was initially creating the listBox at 0,0,0,0, then setting the position and size later in the program. Of course I was able to work around this by setting an initial size greater than 10, but I thought I should let you know.

Comment #3

Posted on Nov 13, 2010 by Swift Hippo

I did look at the code and it would be easy enough to fix if you change your mind.

ListBox.java

80 _myBackgroundHeight = theH; //You could do a simple _myBackgroundHeight = theH < 10 ? 10;

Comment #4

Posted on Nov 13, 2010 by Swift Hippo

Opps.. these comments should allow edit. (also I'm not that great at Java shorthand, so double check the statement).

ListBox.java

80 _myBackgroundHeight = theH; //You could do a simple _myBackgroundHeight = theH < 10 ? 10 : theH;

Status: WontFix

Labels:
Type-Defect Priority-Medium