Add callbacks for components


#1

Hi Jules, I’ve used your library, I liked it very much. But there are drawbacks, such as for me it would be easier to add callbacks than anything in the function. It would be nice if you added it. Sorry for my english, I do not know much of it.


#2

Sorry, really not sure what you’re asking there!

Do you mean lambdas? If so we’re certainly keen to add more use of them, it’s something we’ll be doing more of this year.


#3

Yes it is, I mean,
Here is an example:

void click(Button *b){}
button->onClick = click;

It very comfortable.


#4

You can of course already implement your own lambda/std::function based callbacks system on top of the existing components…

Still, it would be preferable if Juce itself started adopting that kind of stuff. :yum:


#5

Need to try. I think it would be better if it was in JUCE.


#6

a couple different style of Signal/Slot systems have been presented by the forum community: Signals & slots in Juce

Take a look at this thread.


#7

I JUST did this exact thing last night and it works really well with JUCE components. I’m not done yet, but all the components I’ve added std::func/lambdas to so far have been structured to where it’s really easy to do aside from having to move a bunch of the base components’ stuff from private to protected.


#8

@SonicZentropy
Can you delve a bit deeper and explain what you mean for how you got juce::Components to accept lambdas/std::function<>'s as replacements for mouseDown/Move/Over/Exit/Enter/etc…