-
Notifications
You must be signed in to change notification settings - Fork 35
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
Maybe change Event to be an interface instead of struct? #4
Comments
Thanks a lot for thinking about this! There is one more benefit to the original string events that you don't cover here and that's this: switch {
case event.Matches("kb/down/left"):
// ...
case event.Matches("kb/down/right"):
// ...
} Matching directly on the values of the event, like specific keys. We don't necessarily need to address it, but it would be nice. |
Handling the args can be done in a second switch; for example if you want to do something when the letter switch event.Name() {
case gui.EventKeyboardChar:
switch event.Args().(rune) {
case 'q':
win.Close()
}
} And in a case for switch event.Args().(string) {
case "up":
gfx.Log("↑")
case "down":
gfx.Log("↓")
case "left":
gfx.Log("←")
case "right":
gfx.Log("→")
} |
Yeah, I know, but that requires another switch, you know. It's quite nicer to have to all in a single switch. |
Btw, what do you think about something as straightforward as this? type Event interface{}
type EventResize struct {
Bounds image.Rectangle
}
type EventKbDown struct {
Key string
}
type EventMoMove struct {
Point image.Point
}
// more event types |
And perhaps adding a |
Then you would be back to using a concrete type for each event instead of an interface that could be implemented by someone else. |
Yeah, but an event is just data, right? I'm not sure a single type of event needs multiple implementations. And adding more types of events would be easy, just add a new event type. |
Perhaps I'm missing some of your points :D |
I'll continue experimenting to see what I come up with :) Thank you for creating this project, it is very close to exactly what I've wanted when displaying my github.com/peterhellberg/gfx experiments. |
Thanks! I appreciate that a lot. I also appreciate your feedback and suggestions. |
Have you figured something out? I think I'll try the structs, see how it goes. |
Not much, other than deciding to rename the Args field to Data :) // Event includes its name and data.
type Event interface {
Name() string
Data() interface{}
} I've started to think a bit about how/if it would make sense to being able to trigger custom events (on a timer, when receiving data over the network, etc.) Will probably not have that much time tonight though. |
With concurrent GUI, you can solve that kind of thing simply with channels :). You make a long running thing send a value over a channel and you select on that channel alonside selecting on the events channel. |
I decided to give concrete event types a try. |
Ok :) |
I'm thinking something along these lines:
This would look like this when in use:
I will experiment a bit more, but so far I've reduced the code in this project to a single file (in order to help with the experimentation)
The text was updated successfully, but these errors were encountered: