You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void draw() {
// No need to draw the background here
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isAssignableFrom(CustomToggleButton.class)) {
// Change the background color based on the button state
background(toggleButton.isActive() ? 0 : 255);
}
}
public static void main(String[] args) {
PApplet.main("TESTE_ControlP5_SWITCH");
}
}
//
While the CustomToggleButton class code is:
import controlP5.*;
public class CustomToggleButton extends Controller {
public CustomToggleButton(ControlP5 cp5, String theName) {
super(cp5, theName);
setWidth(60).setHeight(30);
//setPosition(width / 2 - 30, height / 2 - 15);
}
public void draw(PGraphics g) {
g.noStroke();
// Determines the background color based on the button state
g.background(isActive ? 255 : 0);
// Button background color (opposite to background)
g.fill(isActive ? 0 : 255);
// Draw the button
g.rect(width/2, height/2, 60, 30, 100);
// Indicator circle color
g.fill(148, 56, 173);
// Indicator circle position
float indicatorX = isActive ? width/2 + 15 : width/2 + width - 15;
float indicatorY = height/2 + height / 2;
// Draw the indicator circle
g.ellipse(indicatorX, indicatorY, height - 10, height - 10);
}
}
//
Please help me if possible, I don't know if I'm making some stupid mistake, but I would really appreciate a solution
My goal is to create something like the one in the image.
The text was updated successfully, but these errors were encountered:
I'm trying to create a custom rounded toggle switch, but I'm encountering the second error:
The function add(CustomToggleButton) does not exist.
//
The main code of the program that I named TESTE_ControlP5_SWITCH is the following:
import controlP5.*;
public class TESTE_ControlP5_SWITCH extends PApplet {
ControlP5 cp5;
CustomToggleButton toggleButton;
void setup() {
size(500, 500);
cp5 = new ControlP5(this);
}
void draw() {
// No need to draw the background here
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isAssignableFrom(CustomToggleButton.class)) {
// Change the background color based on the button state
background(toggleButton.isActive() ? 0 : 255);
}
}
public static void main(String[] args) {
PApplet.main("TESTE_ControlP5_SWITCH");
}
}
//
While the CustomToggleButton class code is:
import controlP5.*;
public class CustomToggleButton extends Controller {
public CustomToggleButton(ControlP5 cp5, String theName) {
super(cp5, theName);
setWidth(60).setHeight(30);
//setPosition(width / 2 - 30, height / 2 - 15);
}
public void draw(PGraphics g) {
g.noStroke();
}
}
//
Please help me if possible, I don't know if I'm making some stupid mistake, but I would really appreciate a solution
My goal is to create something like the one in the image.
The text was updated successfully, but these errors were encountered: