Replies: 1 comment
-
The code is as follows package main
import (
"fmt"
g "github.com/AllenDang/giu"
)
var b = 0
var _ g.Widget = &EventAttribute{}
var refTable = map[string]g.Widget{}
type EventAttribute struct {
id string
event *g.EventHandler
}
func (p *EventAttribute) Build() {
p.event.Build()
}
func (p *EventAttribute) OnKeyDown(key g.Key, fn func()) *EventAttribute {
p.event.OnKeyDown(key, fn)
return p
}
func CreateEvent() *EventAttribute {
var id = g.GenAutoID("EventAttribute")
if widget, ok := refTable[id]; ok {
return widget.(*EventAttribute)
} else {
refTable[id] = &EventAttribute{
event: g.Event(),
}
return refTable[id].(*EventAttribute)
}
}
func loop() {
g.SingleWindow().Layout(
g.Child().Size(-1, -1),
CreateEvent().OnKeyDown(g.KeyS, func() {
b++
fmt.Println(b)
}),
)
}
func main() {
g.SetDefaultFontSize(18)
wnd := g.NewMasterWindow("TestWindow", 800, 480, 0)
wnd.Run(loop)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Just now, I tried to customize an event. In the process, I found that an event would be triggered more than ten or even hundreds of times. Why? I did not encounter this problem in the predefined event
I want to know what I wrote wrong?
Beta Was this translation helpful? Give feedback.
All reactions