airstruck / luigi

Lovely User Interfaces for Game Inventors
MIT License
114 stars 23 forks source link

Implement `Focus` event. #62

Closed ndarilek closed 5 years ago

ndarilek commented 5 years ago

Thanks for building one of the only keyboard-navigable Love UIs! :) I need to be able to track, on the layout level, when a given widget gains focus.

This support may need to be fleshed out further, but for now this lets me do that. Not sure if we should add an Unfocus event as well?

airstruck commented 5 years ago

This seems like a good idea. I think unfocus makes sense for symmetry. It's called "blur" in some libraries; either name would be fine.

The line Event['Focus']:emit(self.layout, self) should be written as Event.Focus:emit(self.layout, self) for consistency.

If you don't mind adding unfocus/blur and that minor style change and updating the PR, I'll go ahead and pull it. 👍

ndarilek commented 5 years ago

Done.

BTW, I'd like to add other events too. In particular, I'd like to track when layouts are shown/hidden. Hope that's OK with you. :)

airstruck commented 5 years ago

That Blur event is called on the wrong widget, no?

Should look something like local blurredWidget = layout.focusedWidget ... (nil some things out) ... Event.Blur:emit(layout, blurredWidget) instead.

Feel free to submit PRs with more events, had planned to add them as needed.

ndarilek commented 5 years ago

Good catch, didn't need the event myself so haven't tested that. Should be fixed now.