- Notifications
You must be signed in to change notification settings - Fork1.4k
/
Copy pathmenu.go
93 lines (82 loc) · 2.28 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package fyne
typesystemTrayDriverinterface {
Driver
SetSystemTrayMenu(*Menu)
SystemTrayMenu()*Menu
}
// Menu stores the information required for a standard menu.
// A menu can pop down from a [MainMenu] or could be a pop out menu.
typeMenustruct {
Labelstring
Items []*MenuItem
}
// NewMenu creates a new menu given the specified label (to show in a [MainMenu]) and list of items to display.
funcNewMenu(labelstring,items...*MenuItem)*Menu {
return&Menu{Label:label,Items:items}
}
// Refresh will instruct this menu to update its display.
//
// Since: 2.2
func (m*Menu)Refresh() {
for_,w:=rangeCurrentApp().Driver().AllWindows() {
main:=w.MainMenu()
ifmain!=nil {
for_,menu:=rangemain.Items {
ifmenu==m {
w.SetMainMenu(main)
break
}
}
}
}
ifd,ok:=CurrentApp().Driver().(systemTrayDriver);ok {
ifm==d.SystemTrayMenu() {
d.SetSystemTrayMenu(m)
}
}
}
// MenuItem is a single item within any menu, it contains a display Label and Action function that is called when tapped.
typeMenuItemstruct {
ChildMenu*Menu
// Since: 2.1
IsQuitbool
IsSeparatorbool
Labelstring
Actionfunc()`json:"-"`
// Since: 2.1
Disabledbool
// Since: 2.1
Checkedbool
// Since: 2.2
IconResource
// Since: 2.2
ShortcutShortcut
}
// NewMenuItem creates a new menu item from the passed label and action parameters.
funcNewMenuItem(labelstring,actionfunc())*MenuItem {
return&MenuItem{Label:label,Action:action}
}
// NewMenuItemSeparator creates a menu item that is to be used as a separator.
funcNewMenuItemSeparator()*MenuItem {
return&MenuItem{IsSeparator:true,Action:func() {}}
}
// MainMenu defines the data required to show a menu bar (desktop) or other appropriate top level menu.
typeMainMenustruct {
Items []*Menu
}
// NewMainMenu creates a top level menu structure used by fyne.Window for displaying a menubar
// (or appropriate equivalent).
funcNewMainMenu(items...*Menu)*MainMenu {
return&MainMenu{Items:items}
}
// Refresh will instruct any rendered menus using this struct to update their display.
//
// Since: 2.2
func (m*MainMenu)Refresh() {
for_,w:=rangeCurrentApp().Driver().AllWindows() {
menu:=w.MainMenu()
ifmenu!=nil&&menu==m {
w.SetMainMenu(m)
}
}
}