Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minigui docs: event handler must be a delegate #475

Open
whitebyte opened this issue Jan 2, 2025 · 4 comments
Open

minigui docs: event handler must be a delegate #475

whitebyte opened this issue Jan 2, 2025 · 4 comments

Comments

@whitebyte
Copy link

https://dpldocs.info/experimental-docs/arsd.minigui.Event.html

Trying to actually compile an example from this page

widget.addEventListener((KeyDownEvent ev) { ... }, /* optional arg */ useCapture );

throws arsd/minigui.d(1416): Error: static assert: "Your handler wasn't usable because it wasn't passed a delegate. Use the delegate keyword at the call site."

Marking lambda as a delegate solves the issue:

widget.addEventListener(delegate(KeyDownEvent ev) { ... }, /* optional arg */ useCapture );

no biggie but it's worth mentioning in the docs.
Also, useCapture isn't documented anywhere

@adamdruppe
Copy link
Owner

yeah if you use local variables it is automatically a delegate so in most cases it will work but an empty function (or just a writeln logger) won't.

useCapture means the event is triggered on the capture phase instead of the bubble phase. the docs talk about this but it is mostly a javascript thnig you can look up too

maybe ill rewrite that soon

@whitebyte
Copy link
Author

it will work but an empty function (or just a writeln logger) won't.

That was exactly my case. I just slapped a writeln to check if it works. Then why minigui insists on a delegate? If a programmer is ok with a plain function that doesn't capture context, minigui should also be ok

@adamdruppe
Copy link
Owner

It just requires adding like 12 function overloads for the function to delegate adapters.... easier to just put the word at the call site lol

@adamdruppe
Copy link
Owner

OpenD could probably implicitly convert function to delegate, codegen wise you can do it and there's no loss of information (you can do it in library too, put a thunk in the funcptr then ptr is the actual funcptr). So solid maybe putting that right in the compiler but might also cause side effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants