Great, thanks.
When an item is selected from teh dropdown I needed to use the controlEvent to trigger updates to setIndex and isOpen to get the control to behave as I wanted, but once I had realised this it works perfectly.
For anyone else trying this, here is a snippet of how I got this working.
- public class SomeControls
- {
- ControlGroup cg;
- MyDropdownList WaveSelector;
-
- public SomeControls(CustomWave[] waves)
- {
- cg = controlP5.addGroup("ctrlGroup", 0, 0);
-
- //Create a MyDropdownList for selecting a specific wave
- WaveSelector = new MyDropdownList(controlP5, cg, "WavePicker", 10, 20, 100, 120);
-
- //Add the waves to the dropdown
- for(int i = 0; i < theWaves.length; i++) {
- WaveSelector.addItem("Wave " + (i+1),i);
- }
-
- //Dropdown will be expanded by default if no initial state is set
- WaveSelector.setOpen(false);
- }
-
- //Programatically set the selected dropdown value
- //Note: This does not fire a controlEvent so any logic needs to be handled elsewhere if required
- public void SelectWave(int index)
- {
- WaveSelector.setIndex(index);
- WaveSelector.setOpen(false);
- }
- }
- //handle controlEvents from the ControlP5 library controls
- void controlEvent(ControlEvent theEvent)
- {
- if (theEvent.isGroup()) {
- if (debug) println("P5 Group controlEvent: " + theEvent.group().name() + ": " + (int)theEvent.group().value());
-
- //Set up for wave picker
- if (theEvent.group().name() == "WavePicker")
- {
- MyControls.SelectWave((int)theEvent.group().value());
- }
- }
- }
Phil