pass function to Button Object

Hey all,

I know there are a couple of gui projects already started, but i’ve been working on my own as well. partly to organize my own code, partly to improve my knowledge.
I just updated to a newer build of OF and am starting to learn about the Poco stuff and the listerner objects.

my question is this: what is the best (easiest?most logical? most efficient?) way to connect a function in (my test.cpp) with a button or other gui object that I want to trigger that function? so for exmaple, i have a button, and when i press that button I want it to save what’s on my screen. Is this something i want to use poco / events for? or do i want to use a callback (which i havent learned yet) or do i want to do something else? i can make it work, but i would like to know what the best practice would be.



There’s no gui addon that supports events right now. I think that’s the way to go.

You can use some callbacks but in c++ is complicated, as once you define a callback to a function inside a class you need to always call that class, you can not cast the callback to a diferent one.

I’m working in some refactoring in the events stuff and one of the addons i’m testing with is the gui, so i expect the gui in 006 will have events.

Another vote for events, it will make your life a lot easier.

If you want to pass a function to an object you can have a look at how it works here:

And here is my old UI library that does that:…

Events are probably not the most efficient way to do it, so if you ever need to do something like that in a performance critical section of your projects I’d guess function pointers are the way to go.

For everything else, I’d do events.