dontpanic92 / wxGo

Golang wxWidgets Wrapper
Other
403 stars 51 forks source link

Failed to convert wx.Event to wx.MouseEvent in wx.EVT_LEFT_DCLICK #46

Closed xinhuang closed 6 years ago

xinhuang commented 6 years ago

I have following code snippet to handle double clicks:

wx.Bind(panel, wx.EVT_LEFT_DCLICK, func(e wx.Event) {
    mouseEvt := wx.MouseEvent(e)
    // ...
}

But the compiler complains about the conversion:

./main.go:12:28: cannot convert e (type wx.Event) to type wx.MouseEvent:
    wx.Event does not implement wx.MouseEvent (missing AltDown method)

I checked wxGo/src/wxGoInterface/event.h but didn't find AltDown method in wx.MouseEvent. Is there anything I did wrong?

Thanks!

dontpanic92 commented 6 years ago

Please try to use wx.ToMouseEvent(e), which is something like reinterpret_cast<wxMouseEvent*> in C++. Types are erased during callback.

BTW, it is invalid to use "type conversion" to convert a base interface into a "derived" interface in Go. Instead, you should use "type assertion": x.(T). However, as the types are erased, this type assertion way also won't work in wxGo callback functions.

xinhuang commented 6 years ago

Oh sorry. That's a silly mistake. The C++ part of my brain just jumped in to my go program. :P