Created
May 28, 2020 03:27
-
-
Save moebiussurfing/794c3ba9905bbfeee939318001497304 to your computer and use it in GitHub Desktop.
openFrameworks / ImGui helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// my own helper | |
template<typename ParameterType> | |
bool AddParameter(ofParameter<ParameterType>& parameter); | |
// my own helper | |
//-------------------------------------------------------------- | |
template<typename ParameterType> | |
bool ofApp::AddParameter(ofParameter<ParameterType>& parameter) | |
{ | |
auto tmpRef = parameter.get(); | |
const auto& info = typeid(ParameterType); | |
//convert string to char pointer | |
string _str = parameter.getName(); | |
const char * _name(_str.c_str()); | |
if (info == typeid(float)) | |
{ | |
if (ImGui::SliderFloat(_name, (float *)&tmpRef, parameter.getMin(), parameter.getMax())) | |
{ | |
parameter.set(tmpRef); | |
return true; | |
} | |
return false; | |
} | |
if (info == typeid(int)) | |
{ | |
if (ImGui::SliderInt(_name, (int *)&tmpRef, parameter.getMin(), parameter.getMax())) | |
{ | |
parameter.set(tmpRef); | |
return true; | |
} | |
return false; | |
} | |
if (info == typeid(bool)) | |
{ | |
if (ImGui::Checkbox(_name, (bool *)&tmpRef)) | |
{ | |
parameter.set(tmpRef); | |
return true; | |
} | |
return false; | |
} | |
ofLogWarning(__FUNCTION__) << "Could not create GUI element for type " << info.name(); | |
return false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment