Search code examples
processingcontrol-p5

Collapse ControlP5 DropdownList


I am having issues collapsing a ControlP5 DropdownList object.

I select the item that I want, the arrow points up as if it wanted to collapse....but all of the choices are still there! It never collapses after a selection is made.

I have looked at the isOpen() function and it is telling me that the list is closed. I have also explored the isCollapse() function and it is telling me that the list is already collapsed......

Here is my code for instantiating the object:

    SimilarityChoices = P5Controller.addDropdownList("SimChoices").setPosition((float)(width * .7), 450);
    SimilarityChoices.addItem("Euclidian", 1);
    SimilarityChoices.addItem("Manhattan", 2);
    SimilarityChoices.setValue(2);      
    this.SimilarityChoices.enableCollapse();
    this.SimilarityChoices.setItemHeight(20);
    this.SimilarityChoices.actAsPulldownMenu(true);

If anybody can give me a hint on how to make this work, I'd be much obliged. (And I'm happy to supply more information as well)


Solution

  • You'll notice that the dropdownlist example sketch includes this:

    void draw() {
      background(128);
    }
    

    which draws over the pixels previously rendered while the list was expanded. I wrote a sketch using your code to illustrate the difference more clearly:

    import controlP5.*;
    
    ControlP5 P5Controller;
    DropdownList SimilarityChoices;
    
    void setup() {
      size(500, 500);
      P5Controller = new ControlP5(this);
      SimilarityChoices = P5Controller.addDropdownList("SimChoices").setPosition((float)(width * .7), 450);
      SimilarityChoices.addItem("Euclidian", 1);
      SimilarityChoices.addItem("Manhattan", 2);
      SimilarityChoices.setValue(2);      
      this.SimilarityChoices.enableCollapse();
      this.SimilarityChoices.setItemHeight(20);
      this.SimilarityChoices.actAsPulldownMenu(true);
    }
    void draw() {
      //background(128);
    }
    

    Uncommenting the background(128); line makes it behave as expected. I hope that helps! Note that some of the settings you coded in may no longer be necessary.