Skip to content

Instantly share code, notes, and snippets.

@moebiussurfing
Created May 28, 2020 03:27
Show Gist options
  • Save moebiussurfing/794c3ba9905bbfeee939318001497304 to your computer and use it in GitHub Desktop.
Save moebiussurfing/794c3ba9905bbfeee939318001497304 to your computer and use it in GitHub Desktop.
openFrameworks / ImGui helper
// 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