Multi canvas with ofxUI

Hello,
I have got some problems with GUI in class.
On the guiEvent in the ofProjecteur class the variable etat is not change. Is it a ofxui problem, a addListener or me ?

testApp

  
  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){  
	console = new ofxUICanvas(0,600,200,100);  
	console->addWidgetDown(new ofxUIButton(32, 32, false, "PROJECTEUR +"));  
	ofAddListener(console->newGUIEvent, this, &testApp::guiEvent);  
	myfont.loadFont("arial.ttf", 12);  
}  
  
void testApp::guiEvent(ofxUIEventArgs &e) {  
	if (e.widget->getName() == "PROJECTEUR +") {  
		ofxUIImageButton *button = (ofxUIImageButton *) e.widget;  
		if (button->getValue()) {  
			projo.push_back(ofProjecteur(projo.size() * 110, 0, projo.size()));  
		}  
	}  
}  
  
void testApp::exit() {  
	delete console;  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
	  
}  
  
//--------------------------------------------------------------  
void testApp::draw() {  
	for (int i = 0; i < projo.size(); i++) {  
		myfont.drawString(ofToString(projo[i].etat), projo[i].x , 400);  
	}  
}  
  

ofProjecteur

  
  
#include "ofProjecteur.h"  
  
using namespace std;  
  
ofProjecteur::ofProjecteur(int _x, int _y, int _projecteurId) {  
	x = _x;  
	y = _y;  
	projecteurId = _projecteurId;  
	etat = false;  
	  
	gui = new ofxUICanvas(x, y, 100, 100);  
	stringstream s;  
	s << projecteurId;  
	string nom = "PROJECTEUR " + s.str();  
	gui->addWidgetDown(new ofxUILabel(nom, OFX_UI_FONT_SMALL));  
	gui->addWidgetDown(new ofxUIToggle(20, 20, false, "POWER"));  
	ofAddListener(gui->newGUIEvent, this, &ofProjecteur::guiEvent);  
}  
  
void ofProjecteur::exit() {  
	delete gui;  
}  
  
void ofProjecteur::guiEvent(ofxUIEventArgs &e) {  
	if(e.widget->getName() == "POWER") {  
        ofxUIToggle *toggle = (ofxUIToggle *) e.widget;  
		etat = toggle->getValue();  
    }  
}  
  

src.zip

Where do you change the value ?

The boolean etat is change in the ofProjecteur class in the guiEvent méthod
etat = toggle->getValue();

I can change a variable when the gui is in the testApp but not in a class.
In the script :
http://codelab.fr/viewtopic.php?pid=22953#p22953
I use this method :
bool ofProjecteur::projecteurActif() {
return ( (ofxUILabelToggle *) gui->getWidget(“POWER”) )->getValue();
}

To return the state of the Toggle, but it is not sweet for me.

is the toggle visualy active when clicked ?

also, maybe you have to test :

if (toggle->getValue() == true)

in the event, otherwise buttons and/or toggles states are changed twice : when clicked AND when released.

Yes, I have already test everything even the variable etat binding to the toggle.

  
  
gui->addWidgetDown(new ofxUIToggle(20, 20, &etat, "POWER", OFX_UI_FONT_SMALL));  
  

Nothing change the state of etat.

Ok I have my answer. I need to use pointer to dynamically instantiate my class.
testApp.h

  
  
vector<ofProjecteur*> projo;  
  

testApp.cpp

  
  
ofProjecteur *p = new ofProjecteur(projo.size() * 110, 0, projo.size());  
projo.push_back(p);  
  

Thanks Rezaali