forked from gogpu/gogpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.go
More file actions
90 lines (78 loc) · 1.84 KB
/
Copy pathmenu.go
File metadata and controls
90 lines (78 loc) · 1.84 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package gogpu
import "github.com/gogpu/gogpu/internal/platform"
// MenuRole maps to standard menu items.
type MenuRole int
const (
RoleNone MenuRole = iota
RoleAbout
RolePreferences
RoleServices
RoleHide
RoleHideOthers
RoleShowAll
RoleQuit
RoleClose
RoleMinimize
RoleZoom
RoleFullScreen
RoleBringAllToFront
)
// MenuItem represents a single item in a menu.
type MenuItem struct {
Title string
Action func()
Role MenuRole
Disabled bool
Separator bool
Submenu *Menu
}
// Menu represents a top-level menu.
type Menu struct {
Title string
Items []MenuItem
}
// NewMenu creates an empty menu.
func NewMenu() *Menu {
return &Menu{}
}
// NewMenuWithTitle creates an empty menu with the specified title.
func NewMenuWithTitle(title string) *Menu {
return &Menu{Title: title}
}
// AddItem appends an item to the menu and returns the menu for chaining.
func (m *Menu) AddItem(item MenuItem) *Menu {
m.Items = append(m.Items, item)
return m
}
// SystemMenu identifies a standard macOS menu that can be extended.
type SystemMenu int
const (
SystemMenuApplication SystemMenu = iota
SystemMenuWindow
)
// SystemMenuHandle allows adding items to a system menu.
type SystemMenuHandle struct {
manager platform.PlatMenuManager
menu platform.SystemMenu
app *App
}
// AddItem appends a new item to the system menu.
func (h *SystemMenuHandle) AddItem(item MenuItem) bool {
if h.manager != nil {
return h.manager.AddToSystemMenu(h.menu, []platform.MenuItem{{
Title: item.Title,
Action: item.Action,
Role: platform.MenuRole(item.Role),
Disabled: item.Disabled,
Separator: item.Separator,
}})
}
if h.app != nil && h.app.pendingSystemMenuItems != nil {
h.app.pendingSystemMenuItems[SystemMenu(h.menu)] = append(
h.app.pendingSystemMenuItems[SystemMenu(h.menu)],
item,
)
return true
}
return false
}