controlP5 ListBox selection active colour.

edited November 2013 in Library Questions

I want a selected ListBox item appear in red and stay that way until I make another selection. How can I do this? At the moment it stays red as I click and hold down the mouse key then reverts to the original background color after I have let go. Is this the function of the method .setColorActive()?, or should it permanently change to the color I specified after it has been clicked? My code is below. Thanks.

list = controlp5.addListBox("LIST")
      .setPosition(130, 40)
      .setSize(100, 150)
      .setItemHeight(20)
      .setBarHeight(20)
      .setColorBackground(color(40, 128))
      .setColorActive(color(255, 0, 0))

Answers

  • .setColorActive is for when the mouse is clicked as you describe

    what you want is .setColorForeground which would be the selected item

    .setColorBackground would then of course be for items not selected.

  • edited December 2013

    Hi, please have a look at this work-in-progress version and the new ScrollableList, see example below in which the most recent clicked item stays highlighted.

    import controlP5.*;
    // example for processing 2.x and controlP5 2.1 or higher
    void setup() {
    
      size( 400 , 800 );
      ControlP5 cp5 = new ControlP5( this );
      ScrollableList l = cp5.addScrollableList("hello");
      l.setBackgroundColor( color( 255 , 128 ) )
       .setColorBackground( color(200) )
       .setColorForeground( color(235) )
       .setColorActive( color(255) )
       .setColorValueLabel( color(100) )
       .setColorCaptionLabel( color(50) )
       .setPosition( 100 , 100 )
       .setSize( 200 , 200 )
       .setItemHeight( 30 )
       .setBarHeight( 20 )
       .setType(ScrollableList.LIST);
    
    
         for(int i=0;i<50;i++) {
           l.addItem( "a"+i , i );
         }
    }
    
    
    void draw() {
      background(180);
    }
    
    public void controlEvent(ControlEvent ce) {
      println(ce);
    }
    
Sign In or Register to comment.