Hi guys, beginner here. This test code aims at opening a list with 3 items and when one of them is selected, the list should close. also when tapping outside the list, it should close.
but what I am seeing is that the list opens the first time I tap it when I open the app, but if I tap outside the list while it is open, all seems to get out of sync, and I need to tap twice. after that, sometimes I also need to tap the items twice. There is obviously something I am missing and I cannot figure out why this is happening.
It seems to me that when I tap the list the first time, it might register as if an item was tapped? Anyway, here is the code, and please be gentle, as I said I am a beginner. Thank you in advance for your help.
import io.inventit.processing.android.serial.Serial;
//import java.io.File;
import controlP5.*;
import java.util.*;
ControlP5 cp5;
Serial myPort;
PFont font, font1, font2, font3, font4, font5;
//ListBox Menu1;
ScrollableList Menu1;
int read_data[];
void setup() {
clear();
read_data = new int[8192];
size(1024, 2048); // Create Window
font = createFont("Arial Bold", 18);
font1 = createFont("Arial Bold", 10);
font2 = createFont("Arial Bold", 13);
font3 = createFont("Arial Bold", 12);
font4 = createFont("Arial Bold", 19);
font5 = createFont("Arial Bold", 26);
cp5 = new ControlP5(this);
//cp5.getWindow().setPositionOfTabs(71, 0);
List l = Arrays.asList("Open Eeprom", "Save Eeprom", "Exit");
//********************** MENU LISTS **************************
Menu1 = cp5.addScrollableList("File Menu")
.setType(ScrollableList.LIST)
.setPosition(1, 1)
.setSize(200, 500)
.setBarHeight(100)
//.setHeight(500)
.setItemHeight(100)
.addItems(l)
.setFont(font5)
.setColorBackground(color(216, 216, 216))
.setColorForeground(color(232, 232, 232))
.setColorActive(color(186, 188, 188))
.setColorLabel(color(0, 0, 0))
.setColorValueLabel(color(0, 0, 0))
.setColorCaptionLabel(color(0, 0, 0))
.setOpen(false);
;
//Menu1.bringToFront();
Menu1.getCaptionLabel().toUpperCase(true);
//Menu1.getCaptionLabel().set("File Menu");
Menu1.getCaptionLabel().align(CENTER, CENTER);
}
//***************************** MAIN LOOP *********************************
void draw() {
background(0, 120, 255); // Background Color (r, g, b) or (0 to 255)
textFont(font4);
//if (Menu1.isMousePressed()) {
// Menu1.bringToFront();
//}
}
void controlEvent(ControlEvent theControlEvent) {
if (theControlEvent.isController()) {
if (theControlEvent.isFrom(Menu1)) {
int MenuItem = int(theControlEvent.getController().getValue());
if (MenuItem == 0) {
Menu1.close();
}
if (MenuItem == 1) {
Menu1.close();
}
if (MenuItem == 2) {
Menu1.close();
System.exit(0);
}
}
}
}
void mouseReleased() {
if (Menu1.isMouseOver()) {
if (!Menu1.isOpen()) {
delay(100); // Small delay to prevent immediate close
Menu1.open();
}
} else {
Menu1.close();
}
}