So, over in the thread about Signals and Slots here I said that it would be great if component::mouseDown() could be implemented this way: component.mouseDown = []() { DBG("component mouseDown"); };
So, digging a little bit deeper into how mouse events are sent out from the mouseEventSource to the listeners, i ended up at this method:
I realize the tricky part is that the sendMouseEvent() function calls void (MouseListener::*eventMethod)(const MouseEvent& e) for every component that added themselves as a listener to this particular mouseEvent. Perhaps I am just requesting a pipe dream…
But it is 2017, juce5 is using C++11, so shouldn’t we be able to write easier to read code without writing massive if(button == &myButton) switches inside the buttonClicked() callback when our GUI has lots of buttons?
I began my search here for understanding how mouseEvents make their way to a component
void Component::internalMouseDown (MouseInputSource source, Point<float> relativePos, Time time, float pressure)
where a mouseDown(me) is called, followed by MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseDown, me);
Yeah, it’s a good request, but you could also roll your own implementation in a few lines of code without any changes to juce itself. Just create a class that inherits from MouseListener, and contains lambdas to call for each callback, then add that to your component, e.g.