• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fyne-io / fyne / 18807176232

25 Oct 2025 06:34PM UTC coverage: 61.057% (-0.004%) from 61.061%
18807176232

Pull #5989

github

Jacalz
Fix TODO regarding comparable map key
Pull Request #5989: RFC: Proof of concept for upgrading Go to 1.24

155 of 188 new or added lines in 62 files covered. (82.45%)

27 existing lines in 6 files now uncovered.

25609 of 41943 relevant lines covered (61.06%)

692.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.03
/menu.go
1
package fyne
2

3
import "slices"
4

5
type systemTrayDriver interface {
6
        Driver
7
        SetSystemTrayMenu(*Menu)
8
        SystemTrayMenu() *Menu
9
}
10

11
// Menu stores the information required for a standard menu.
12
// A menu can pop down from a [MainMenu] or could be a pop out menu.
13
type Menu struct {
14
        Label string
15
        Items []*MenuItem
16
}
17

18
// NewMenu creates a new menu given the specified label (to show in a [MainMenu]) and list of items to display.
19
func NewMenu(label string, items ...*MenuItem) *Menu {
2✔
20
        return &Menu{Label: label, Items: items}
2✔
21
}
2✔
22

23
// Refresh will instruct this menu to update its display.
24
//
25
// Since: 2.2
26
func (m *Menu) Refresh() {
×
27
        for _, w := range CurrentApp().Driver().AllWindows() {
×
28
                main := w.MainMenu()
×
29
                if main != nil {
×
NEW
30
                        if slices.Contains(main.Items, m) {
×
NEW
31
                                w.SetMainMenu(main)
×
UNCOV
32
                        }
×
33
                }
34
        }
35

36
        if d, ok := CurrentApp().Driver().(systemTrayDriver); ok {
×
37
                if m == d.SystemTrayMenu() {
×
38
                        d.SetSystemTrayMenu(m)
×
39
                }
×
40
        }
41
}
42

43
// MenuItem is a single item within any menu, it contains a display Label and Action function that is called when tapped.
44
type MenuItem struct {
45
        ChildMenu *Menu
46
        // Since: 2.1
47
        IsQuit      bool
48
        IsSeparator bool
49
        Label       string
50
        Action      func() `json:"-"`
51
        // Since: 2.1
52
        Disabled bool
53
        // Since: 2.1
54
        Checked bool
55
        // Since: 2.2
56
        Icon Resource
57
        // Since: 2.2
58
        Shortcut Shortcut
59
}
60

61
// NewMenuItem creates a new menu item from the passed label and action parameters.
62
func NewMenuItem(label string, action func()) *MenuItem {
4✔
63
        return &MenuItem{Label: label, Action: action}
4✔
64
}
4✔
65

66
// NewMenuItemWithIcon creates a new menu item from the passed label, icon, and action parameters.
67
//
68
// Since: 2.7
69
func NewMenuItemWithIcon(label string, icon Resource, action func()) *MenuItem {
×
70
        return &MenuItem{Label: label, Icon: icon, Action: action}
×
71
}
×
72

73
// NewMenuItemSeparator creates a menu item that is to be used as a separator.
74
func NewMenuItemSeparator() *MenuItem {
×
75
        return &MenuItem{IsSeparator: true, Action: func() {}}
×
76
}
77

78
// MainMenu defines the data required to show a menu bar (desktop) or other appropriate top level menu.
79
type MainMenu struct {
80
        Items []*Menu
81
}
82

83
// NewMainMenu creates a top level menu structure used by fyne.Window for displaying a menubar
84
// (or appropriate equivalent).
85
func NewMainMenu(items ...*Menu) *MainMenu {
1✔
86
        return &MainMenu{Items: items}
1✔
87
}
1✔
88

89
// Refresh will instruct any rendered menus using this struct to update their display.
90
//
91
// Since: 2.2
92
func (m *MainMenu) Refresh() {
×
93
        for _, w := range CurrentApp().Driver().AllWindows() {
×
94
                menu := w.MainMenu()
×
95
                if menu != nil && menu == m {
×
96
                        w.SetMainMenu(m)
×
97
                }
×
98
        }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc