Skip to content

Instantly share code, notes, and snippets.

@chaosct
Created April 26, 2014 23:08
Show Gist options
  • Save chaosct/11333512 to your computer and use it in GitHub Desktop.
Save chaosct/11333512 to your computer and use it in GitHub Desktop.
ofxUI better buttons
template<typename F>
class ButtonFunction
{
ofxUIButton * widget;
F f;
public:
ButtonFunction(ofxUIButton * b, F _f):widget(b), f(_f)
{
ofxUICanvas * gui = static_cast<ofxUICanvas*>(widget->getCanvasParent());
ofAddListener(gui->newGUIEvent, this, &ButtonFunction::guiEvent);
}
void guiEvent(ofxUIEventArgs & e)
{
if (e.widget == static_cast<ofxUIWidget*>(widget)
and widget->getValue() == false)
{
f();
}
}
};
template<typename F>
inline ButtonFunction<F> * connectButtonFunction(ofxUIButton * b, F f)
{
return new ButtonFunction<F>(b, f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment