-
Notifications
You must be signed in to change notification settings - Fork 3
/
menu.go
66 lines (54 loc) · 1.16 KB
/
menu.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package goui
/*
#include "menu.h"
*/
import "C"
// MenuType is an enum of menu type
type MenuType int
const (
Container MenuType = iota //just a container item for sub items
Custom
Standard
Separator
)
// MenuDef is to define a menu item
type MenuDef struct {
Type MenuType
Title string
HotKey string
Action string
Handler func()
Children []MenuDef
}
func convertMenuDef(def MenuDef) (cMenuDef C.MenuDef) {
cMenuDef = C.MenuDef{}
cMenuDef.title = C.CString(def.Title)
cMenuDef.action = C.CString(def.Action)
cMenuDef.key = C.CString(def.HotKey)
cMenuDef.menuType = C.MenuType(def.Type)
cMenuDef.children, cMenuDef.childrenCount = convertMenuDefs(def.Children)
return
}
func convertMenuDefs(defs []MenuDef) (array *C.MenuDef, count C.int) {
l := len(defs)
if l == 0 {
return
}
count = C.int(l)
array = C.allocMenuDefArray(count)
for i := 0; i < l; i++ {
cMenuDef := convertMenuDef(defs[i])
C.addChildMenu(array, cMenuDef, C.int(i))
}
return
}
var actionMap map[string]func()
//export menuClicked
func menuClicked(action *C.char) {
a := C.GoString(action)
println("menu clicked", a)
f := actionMap[a]
if f != nil {
f()
}
}