I tell you that I am improving the “GUI” for the flashlight, I want to contribute with the code of this “toogle button” in case someone helps you
verticalToggle VT;
int uX, uY;
color bgColor;
void setup(){
size(400,500);
uX=width/14;
uY=height/14;
//verticalToggle(Xpos, Ypos, width, height, backColor, buttonColor, textColor, TextWhenOFF, textWhenOn);
VT = new verticalToggle(4*uX,uY,6*uX,12*uY,color(127,127,0),color(255,255,0),color(0),"OFF","ON");
}
void draw(){
background(bgColor);
VT.drawToggle();
if(mousePressed || VT.value)bgColor=255;//ON
else bgColor=127;//OFF
}
class verticalToggle{
String lbl1, lbl2;
int x, y, w, h;
float slvalue;
boolean value;
color col, txtCol, color1, color2, textColor;
verticalToggle(int _x, int _y, int _w, int _h, color _color1, color _color2, color _textColor, String _lbl1, String _lbl2){
x=_x;
y=_y;
w=_w;
h=_h;
color1=_color1;
color2=_color2;
textColor=_textColor;
textSize(h/8);
textAlign(CENTER);
lbl1=_lbl1;
lbl2=_lbl2;
}
void drawToggle() {
fill(color1);
rect(x,y,w,h,30);
if(value){
pushMatrix();
translate(x,y);
fill(color2);
rect(0,0,w,h/2,30);
fill(textColor);
textSize(h/8);
textAlign(CENTER);
text(lbl2, (w)/2, (1.3*h)/2);
popMatrix();
}else{
pushMatrix();
translate(x,y);
fill(color2);
rect(0,h/2,w,h/2,30);
fill(textColor);
textSize(h/8);
textAlign(CENTER);
text(lbl1, (w)/2, (1.3*h)/2);
popMatrix();
}
if (mouseX>x && mouseX<x+w && mouseY>y && mouseY<y+h/2) {
if (mousePressed) {
value=true;
}
}else if (mouseX>x && mouseX<x+w && mouseY>y+h/2 && mouseY<y+h) {
if (mousePressed) {
value=false;
}
}
}
}