We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › controlP5 - handle overlapping scroll lists
Page Index Toggle Pages: 1
controlP5 - handle overlapping scroll lists (Read 673 times)
controlP5 - handle overlapping scroll lists
Apr 23rd, 2009, 8:08am
 
Hej,

i want to use several scroll lists in a small amount of space. All lists are closed when the app starts. If one of the list gets expanded it can happen that a choosen button of this list lies directly above the "header button" of another list. So choosing a certain button of one list can accidentally open an other.
Has somebody an idea for a workaround how to avoid this? Is it possible to deactivate the other lists as long one is expanded?

EXAMPLE: Select A3 in the expanded upper list

import controlP5.*;
ControlP5 controlP5;

void setup() {
 size(150,150);
 frameRate(30);
 controlP5 = new ControlP5(this);

 ScrollList list2 = controlP5.addScrollList("myList2",20,80,80,280);
 ScrollList list1 = controlP5.addScrollList("myList",20,30,80,280);
 
 list2.setLabel("lower list");
 for(int i=0;i<4;i++) {
   controlP5.Button b = list2.addItem("a"+i,i);
   b.setId(2);                            
 }
 list2.close();

 list1.setLabel("upper list");
 for(int i=0;i<4;i++) {
   controlP5.Button b = list1.addItem("a"+i,i);
   b.setId(2);                            
 }
 list1.close();

}

void draw() {
 background(255);
}

Re: controlP5 - handle overlapping scroll lists
Reply #1 - Apr 23rd, 2009, 11:12am
 
What I do... and I'm not sure this is the best or proper way to do it, but it works for me.  

I set an id for each scroll list.
Code:

list1.setId(1);
list2.setId(2);

Then in the controlevent
Code:

void controlEvent(ControlEvent theEvent) {
 if(theEvent.isController()) {
   // an event from a controller e.g. button
 }
 else if (theEvent.isGroup()) {
   // an event from a group e.g. scrollList

   if(theEvent.group().id() == 1){
println("list1");
   }
   if(theEvent.group().id() == 2){
println("list2");
   }
 }
}


I also create different control groups for each list, so I can draw each individually.
Code:

ControlP5 controlP5list1, controlP5list2;
...
ScrollList list2 = controlP5list2.addScrollList("L2",20,80,80,280);
ScrollList list1 = controlP5list1.addScrollList("L1",20,80,80,280);

Again, not sure if that's the best way to do it... but it allows me to do a "controlP5list1.draw();" and only draw list1.
Re: controlP5 - handle overlapping scroll lists
Reply #2 - Apr 24th, 2009, 4:03am
 
Hey thanks for your help. I like the strategy with creating several groups. So there is no problem with the event handling - perfect. But  i didn't manage to get rid of my main problem: That a lists which lies "under" a expanded one gets expanded accidetally.  How could i avoid that?
apollo
Re: controlP5 - handle overlapping scroll lists
Reply #3 - Apr 24th, 2009, 5:33am
 
Not sure about that, I guess if the top one is expanded, you could not draw the second scroll list.
Page Index Toggle Pages: 1