Using the following MWE:
import controlP5.*;
import java.util.*;
ControlP5 cp5;
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
/* add a ScrollableList, by default it behaves like a DropdownList */
cp5.addScrollableList("dropdown")
.setPosition(100, 100)
.setSize(200, 100)
.setBarHeight(20)
.setItemHeight(20)
.addItems(l)
// .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
;
}
void draw() {
background(240);
}
How can I change the font color of each list entry separately? I assume I'll have to use a for loop of some kind like the following
for (int i =0; i < myarray.length; i++){
dropdown.setColorActive(elementDetermine(myarray[i]));
}
Where elementDetermine() takes an integer and returns a color. Unfortunately, when I run this loop in either the setup or the draw function, the dropdown list doesn't change without error message.
Unfortunately there's no easy readily available method to change the font color of each list entry separately.
As you can see in the documentation the available methods access the main caption which applies to all items.
In fact, the same
Labelcomponent is re-used accross all list items and simply re-rendered once per item (changing current text/colours) as you can see in the source codeIf you really really need to change the font color you can, but that will be quite a few OOP hoops to jump through (since there is no array of
Labelinstances per item):ControllerView< ScrollableList >to override it'sdisplay()methoddisplay()to work the same as the original ScrollableList you need to pretty much replicate the super classScrollableListsuper class has a bunch of private properties that can easily be accessed from theScrollableListViewclass since it's part ofScrollableList, however in our case all thoseprivate/protectedproperties that need to be accessed indisplay()need to be accessible. To do this aScrollableListsubclass is implemenented (PopUpScrollableList) which mainly replicates it's superclass behaviours wherever thoseprivate/protectedproperties are used indisplay()and also makes them available.Finally the custom scrollable list can have a
color[]which can store the custom colours so they can be accessed and rendered in the overridendisplay()method: