#include /// global gui instance GUI gui; // Our working thread, calling it's run function // asynchronously to the GUI Thread void run(){ // shortcut to extract currentTimeLabel from the gui gui_LabelHandle(currentTimeLabel); currentTimeLabel = Time::now().toString(); Thread::sleep(1); } // a simple callback function of type "void (*callback)(void)" void exit_callback(void){ printf("exit callback was called \n"); exit(0); } // another one (we can also access the GUI from here) void click_callback(){ gui_LabelHandle(currentTimeLabel); currentTimeLabel = "hello!"; } // a more complex callback implementing the GUI::Callback interface // In contrast to simple functions, this callbacks are able to have 'own data' struct MyCallback : public GUI::Callback{ Time m_lastTime; virtual void exec(){ Time now = Time::now(); Time dt = now-m_lastTime; // here we could use the macro gui_LabelHandle(timeDiffLabel) as well gui.getValue("timeDiffLabel") = str(dt.toSecondsDouble())+" sec"; m_lastTime = now; } }; void init(){ // create some nice components gui << "label(something)[@handle=currentTimeLabel@label=current time]" << "label(something)[@handle=timeDiffLabel@label=time since last call]" << "button(Click me!)[@handle=click]" << "button(Click me too!)[@handle=click-2]" << "button(Exit!)[@handle=exit]"; // create and show the GUI gui.show(); /// sometimes, this works as well ! gui["currentTimeLabel"] = Time::now().toString(); // register callbacks (on the specific handles) gui.getValue("exit").registerCallback(new GUI::Callback(exit_callback)); gui.getValue("click").registerCallback(new GUI::Callback(click_callback)); // or let gui find the corresponding components internally gui.registerCallback(new MyCallback,"click-2"); } int main(int n, char **ppc){ return ICLApplication(n,ppc,"",init,run).exec(); }