Problem with ControlP5 library - Button not working

Hello everyone!

I’m working on a GUI for a project I’m working on, and I thought about using ControlP5 as a library to help me adding GUI features (like buttons, sliders and others). I looked up on how it works, implemented few things, everything working just fine… apart from ONE single button.

I don’t know why, every part of it works just fine, not having a single issue on the whole program, apart from that one single button.
And it’s also quite strange, because it seems like it works when I edit something on the code, I can click on it and it does what it’s supposed to do, but if I close the program and try to run it another time without editing the code it just doesn’t work. I can see its animation for being pressed, it changes color, everything works, but the function that should be called when I press the button gets just ignored.

Anyone who could think of a solution? Thanks!

not sure about controlp5 I dont personally make use of it. However you are welcome to try my library.

it is currently in alpha so there may be some bugs

here is an example sketch to showcase functionality. And apologies but I have yet to get round to producing a competent reference document. Please ignore the Window code. That is functionality to add other sketch windows though I havent finalised it.

Anyway

BMS is the class which handles all buttons and gui elements.

Create a new instance.
Thene as per the code below you have to add it to all your gui elements. This will add the item to the BMS arraylist.

BMs is called with Instance.runEmpty() I will update this later. And you also then need to add Instance.theme.run() this is important as it is what handles the mouse and keyboard logic.
Then whatever code you have goes in between those two lines of code.

btn.toggle(object,field);
//this returns a bool on mousePressed
btn.toggle();
//this also returns a bool

BMSinstance.toggle(btnIndex);
//also returns a bool
//if button is in a menu you have to use the menu index of the button
BMSinstance.toggle(menuIndex,btnIndex);
//also returns a bool

Sliders work the same way. You need to access their index in the BMS.

// If its a standalone slider
BMS.set(sliderIndex,startValue,Endvalue);
// If its from a sliderBox menu
BMS.set(sliderBoxIndex,sliderIndex,startValue,Endvalue);

you can also bind the set to an object and field
BMS.set(sliderBoxIndex,sliderIndex,object,field,startValue,Endvalue);

you can also set ints
BMS.setInt(sliderBoxIndex,sliderIndex,startValue,Endvalue);

TextArea ta1,ta2;
	BMS b;
	fileOutput f;
	PGraphics pg;
	tab t1,t2,t3;
	SliderBox sl1,sl2,sl3,sl4,sl5,sl6,sl7,sl8;
	String[] sl1Label = {"1","2","3"};
	String[] ml1Label = {"1,2,3,4"};
	Menu m1,m2,m3,m4;
	Dropdown d1,d2;
	Button b1,b2,b3;
	SWindow w;
	
	public void settings() {
		//		fullScreen();
		size(700, 500);
		
	};

	public void setup() {
		//		
		
		surface.setTitle("TestBench!");
		surface.setResizable(true);
		surface.setLocation(width-20, 0);
		String [] d1l = {"1","2"};
		b = new BMS(this,true);
		b.addWindow(width-5,0,700,500,"New Window");
		b.addWindow(width-5,0,700,500,"New Window");
		t1 = new tab(100,55-30,500,300,"Tab1",b);
		t1.setvScroll();
		t2 = new tab(240,150,200,200,"Tab2",b);
//		b.dock.setRadius(0);
		b.dock.h = 40;
		String []fonts = PFont.list();
		b.setTransparency(100);
//		b.themeSettings.getSliderBox(0).setClassicBar();
		println(fonts);
		d1 = new Dropdown(190,110,90,20,0,"Font",fonts,b);
//		t1.add(d1);
		b1 = new Button(20,330,90,20,"BTN1",b);
		b.add(b1);
		b2 = new Button(240,50,90,20,"BTN2",b);
		t1.add(b2);
		b3 = new Button(20,360,90,20,"BTN3",b);
		b.add(b3);
		sl4 = new SliderBox(200,90,90,90,10,sl1Label,b);
		sl4.setEnd(20);
		sl4.setPieSquare();
//		sl4.setClassicBar();
//		t2.add(sl4);
//		t1.add(sl4);
//		t2.draggable = true;
		t2.toggle = true;
		ta1 = new TextArea(240,20,200,20,"Click",b);
		ta2 = new TextArea(20+220,50,200,20,"Click",b);
		t1.add(ta1);
		b.add(ta2);
//		pg = createGraphics(200,200);
//		
		sl1 = new SliderBox(20,20,90,20,10,sl1Label,b);
		sl1.setEnd(20);
		sl1.setClassicSquare();
		t1.add(sl1);
		
		m1 = new Menu(20,300,90,20,sl1Label,b);
		m1.setClassicBar();
		t1.add(m1);
		m2 = new Menu(60,300,90,20,0,"Menu",sl1Label,b);
		m2.setClassicBar();
		t1.add(m2);
		
		m3 = new Menu(60,330,40,20,0,"Menu",sl1Label,b);
		m3.setClassicBar();
		m3.horizontal = true;
		t1.add(m3);
		
		sl2 = new SliderBox(20,sl1.y+sl1.h+10,90,20,10,sl1Label,b);
		sl2.setEnd(20);
		sl2.setClassicBar();
		t1.add(sl2);
		sl3 = new SliderBox(20,sl2.y+sl2.h+10,90,20,10,sl1Label,b);
		sl3.setEnd(20);
		sl3.setClassicRadio();
		t1.add(sl3);
		//bms
		sl5 = new SliderBox(20,60,90,20,10,sl1Label,b);
		sl5.setEnd(20);
//		b.add(sl5);
//		b.themeSettings.toggle = true;
		sl5.setClassicSquare();
		sl6 = new SliderBox(20,sl5.y+sl5.h+10,90,20,10,sl1Label,b);
		sl6.setEnd(20);
		sl6.setClassicBar();
//		b.add(sl6);
		sl7 = new SliderBox(20,90,90,90,10,sl1Label,b);
		sl7.setEnd(20);
//		sl7.setClassicRadio();
		sl7.setPieSquare();
//		b.add(sl7);
//		b.add(sl4);
		//		sl1.setClassicRadio();
		//		sl1.setPieSquare();
		//b.add(sl1);
//		b.add(t1);
		//		t1.setPos(20, 20);
		//		b.add(t2);
		//b.add(d1);
		t2.draggable = true;
		t2.toggle = true;
		t1.toggle = true;
		t1.draggable = true;
		t1.setvScroll();
		b.add(t1);
		b.add(t2);
//		String[] windows = b.getWindowsAsString();
//		
//		if(windows!=null)d2 = new Dropdown(20,400,90,20,0,"Window",d1l,b);
//		b.add(d2);
	};

	public void draw(){
		background(0,0);
		fill(64);
		rect(0,0,width,height,10);
		//f.listen();
		fill(255);
		t1.setvScroll(0,10);
		t1.set(0,0,0, 10);
		b.run();
//		b.windowState = d2.index;
//		b1.toggle(this,"test");
//		ta2.draw();
//		b3.toggle(b,"openWindow");
		b.theme.run();
//		b.drawThemes();
		fill(0);
		text(frameRate,150,90);
		//println(t1.getSlider(0,1).value);
		//		if(b.toggle(1,0))ellipse(mouseX,mouseY,20,20);
	};

	public void mousePressed() {

		//f.writeLine("hello");
	};

	public static void main(String[] args) {
		PApplet.main(MySketch.class.getName());
	};

	public void keyPressed() {

	};

Hi @ImDaGr3en

It would be helpful if you could post your code so that we can reproduce the error and find the solution :slight_smile:

2 Likes

@MiguelSanches hi

You are creative with controlp5 solutions

Hi @jafal,

I would say that I am used to the library because I spent quite some time reading the documentation. When I started using processing, I was trying to implement GUI’s for real time acquisition with arduino and dashboards, so I found that controlP5 was a nice one to use :slight_smile:

But in general, if I find that I can be helpful in some topic that is somebody else’s question, I am glad to help!

1 Like

@MiguelSanches

I saw most your participation you are creative

1 Like