Help with ofxImGui saving

#1

hello has some one used ofxImGui i been trying to use just to learn of it but i came to a problem can find a way to save the values from the sliders or other like on ofxGui or ofxUI has some one here know how to ?

#2

I usually save/load settings adding all the ofParameters to an ofParameterGroup (that have save load methods). Then you can serialize easy to an xml or json, to load and save at once. With ofxImGui you can use ofParameters, like you can see on the helpers example.

#3

hey so i have it like this but can you explain me how to serialize or what you mean by that?

ofParameterGroup noiseSettings{"Style Settings"};
	ofParameter<float>xFreq{"xFreq", 10.,0.0,128.0};
	ofParameter<float>yFreq{"yFreq", 8.,0.0,128.0};
	ofParameter<float>zFreq{"zFreq", 7.,0.0,128.0};

	ofParameter<float>xDepth{"xFreq", 0.15,0.0,2.0};
	ofParameter<float>yDepth{"yFreq", 0.12,0.0,2.0};
	ofParameter<float>zDepth{"zFreq", 0.18,0.0,2.0};
	//ofParameter<float>speed{"speed", 0.03,0.0,2.0};
#4
// ofApp.h
ofParameterGroup noiseSettings{"Style Settings"};
ofParameter<float>xFreq{"xFreq", 10.,0.0,128.0};
ofParameter<float>yFreq{"yFreq", 8.,0.0,128.0};
ofParameter<float>zFreq{"zFreq", 7.,0.0,128.0};
ofParameter<float>xDepth{"xFreq", 0.15,0.0,2.0};
ofParameter<float>yDepth{"yFreq", 0.12,0.0,2.0};
ofParameter<float>zDepth{"zFreq", 0.18,0.0,2.0};
ofParameter<float>speed{"speed", 0.03,0.0,2.0};

string XML_path = "mySettings/style.xml";
//handy methods to use to many ofParameterGroup's
void XML_load_AppSettings(ofParameterGroup &g, string path);
void XML_save_AppSettings(ofParameterGroup &g, string path);

//-

// ofApp.cpp :: setup() 
// add required parameters to the group
noiseSettings.add(xFreq);
noiseSettings.add(yFreq);
noiseSettings.add(zFreq);
noiseSettings.add(xDepth);
noiseSettings.add(yDepth);
noiseSettings.add(zDepth);
noiseSettings.add(speed);

//when you want to load all parameters states/values
//all the parameters included into noiseSettings group will recall they values from the xml file
XML_load_AppSettings(noiseSettings, XML_path);

// ofApp.cpp :: exit() or when you want to save
XML_save_AppSettings(noiseSettings, XML_path);

//--------------------------------------------------------------
void ofApp::XML_load_AppSettings(ofParameterGroup &g, string path)
{
    ofLogNotice("ofApp") << "XML_load_AppSettings " << path;
    ofXml settings;
    settings.load(path);
    ofDeserialize(settings, g);
}

//--------------------------------------------------------------
void ofApp::XML_save_AppSettings(ofParameterGroup &g, string path)
{
    ofLogNotice("ofApp") << "XML_save_AppSettings " << path;
    ofXml settings;
    ofSerialize(settings, g);
    settings.save(path);
}
1 Like