google / gxui

An experimental Go cross platform UI library.
BSD 3-Clause "New" or "Revised" License
4.44k stars 299 forks source link

Error when run sample on web #171

Open jeenhyung opened 8 years ago

jeenhyung commented 8 years ago

[OSX 10.10.5] when i run gxui sample project on web. but, I get this error:

github.com/google/gxui/drivers/gl/keyboard_translate.go:141:7: duplicate case glfw.KeyEnd (constant -1 of type github.com/goxjs/glfw.Key) in expression switch github.com/google/gxui/drivers/gl/keyboard_translate.go:113:7: previous case github.com/google/gxui/drivers/gl/keyboard_translate.go:145:7: duplicate case glfw.KeyScrollLock (constant -1 of type github.com/goxjs/glfw.Key) in expression switch github.com/google/gxui/drivers/gl/keyboard_translate.go:113:7: previous case github.com/google/gxui/drivers/gl/keyboard_translate.go:147:7: duplicate case glfw.KeyNumLock (constant -1 of type github.com/goxjs/glfw.Key) in expression switch github.com/google/gxui/drivers/gl/keyboard_translate.go:113:7: previous case github.com/google/gxui/drivers/gl/keyboard_translate.go:149:7: duplicate case glfw.KeyPrintScreen (constant -1 of type github.com/goxjs/glfw.Key) in expression switch github.com/google/gxui/drivers/gl/keyboard_translate.go:113:7: previous case github.com/google/gxui/drivers/gl/keyboard_translate.go:151:7: duplicate case glfw.KeyPause (constant -1 of type github.com/goxjs/glfw.Key) in expression switch github.com/google/gxui/drivers/gl/keyboard_translate.go:113:7: previous case github.com/google/gxui/drivers/gl/keyboard_translate.go:113:7: too many errors

Help plz fix this.

dmitshur commented 8 years ago

This looks like a legitimate issue. I suspect it wasn't caught before because the GopherJS had a bug where it did not fail to compile when a switch had duplicate cases (see https://github.com/golang/go/issues/11578 as the upstream issue).

That issue has since been fixed (i.e., https://github.com/gopherjs/gopherjs/issues/269 is resolved), and this Go code is invalid and needs to be fixed for it to compile successfully.

The code to be fixed is here:

https://github.com/goxjs/glfw/blob/3ef83661bf02c111e9f84faada310a95c1762132/browser.go#L638

All those duplicate -1 key constants values are not compatible with the gxui code in keyboard_translate.go. They need to be changed to unique values.

The Web APIs should be consulted in order to give them values compatible with what KeyboardEvents set their keyCode property to. See the keyCode tables at https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode. I will accept a PR to https://github.com/goxjs/glfw that fixes this issue.

dmitshur commented 8 years ago

@jeenhyung, I have fixed the issue in https://github.com/goxjs/glfw/commit/aee868d2f5e3a6875af474ec05c54b2a19d5695d. Please update github.com/goxjs/glfw to latest version and gxui will work in browser.

This issue can be closed.