Last active
May 5, 2020 22:28
-
-
Save moebiussurfing/d1b02b7482b05aeadaab108c1eed5e91 to your computer and use it in GitHub Desktop.
openFrameworks / template for parameter types / ofxImGui example
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
template<typename ParameterType> | |
bool AddParameter(ofParameter<ParameterType>& parameter); | |
//-------------------------------------------------------------- | |
template<typename ParameterType> | |
bool ofxImGui::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()); | |
//_name -> GetUniqueName(parameter) | |
if (info == typeid(float)) | |
{ | |
if (ImGui::SliderFloat(GetUniqueName(parameter), (float *)&tmpRef, parameter.getMin(), parameter.getMax())) | |
{ | |
parameter.set(tmpRef); | |
return true; | |
} | |
return false; | |
} | |
if (info == typeid(int)) | |
{ | |
if (ImGui::SliderInt(GetUniqueName(parameter), (int *)&tmpRef, parameter.getMin(), parameter.getMax())) | |
{ | |
parameter.set(tmpRef); | |
return true; | |
} | |
return false; | |
} | |
if (info == typeid(bool)) | |
{ | |
if (ImGui::Checkbox(GetUniqueName(parameter), (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