in case the user wants to declare the event beforehand or if the user wants a callback only with sender and the event but the event doesn't have an empty ctor
@EventType("ClickEvent") class ClickEvent : Event { this(in size_t x, in size_t y) { this.x = x; this.y = y; } mixin basicEventType!ClickEvent; private : const size_t x, y; } class Foo { mixin genCallback!(const Foo, ClickEvent, const size_t, "x", const size_t, "y") onClicked; // Note: you can leave the parameters blank, if you do, then the event // itself will be passed as the second parameter as const public : void click(in size_t x, in size_t y) { // click stuff here onClicked.emit(x, y); } void onEvent(Event event) { // handle your events here auto dispacher = scoped!EventDispatcher(event); dispacher.dispatch!ClickEvent(&onClicked.dispatch); } } bool onFooClicked(in Foo sender, in size_t x, in size_t y) { // do stuff here assert([x, y] == [4, 5]); // true to handle the event // false to propagate return true; } void main() { Foo foo = new Foo(); foo.onClicked.connect(toDelegate(&onFooClicked)); foo.click(4,5); // callback! }
Generate generic callback functions