PageSourceSearch

https://wails.pages.dev/assets/js/4308349e.0b0b4e75.js

js wails.pages.dev collected 2026-10-03 06:07:13 UTC 20,951 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkwails_website=globalThis.webpackChunkwails_website||[]).push([[5807],{28453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var i=t(96540);const l={},s=i.createContext(l);function r(e){const n=i.useContext(s);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:r(e.components),i.createElement(s.Provider,{value:n},e.children)}},56853:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>c,default:()=>h,frontMatter:()=>r,metadata:()=>i,toc:()=>a});const i=JSON.parse('{"id":"reference/menus","title":"Menus","description":"It is possible to add an application menu to Wails projects. This is achieved by defining a Menu struct and","source":"@site/versioned_docs/version-v2.13.0/reference/menus.mdx","sourceDirName":"reference","slug":"/reference/menus","permalink":"/docs/v2.13.0/reference/menus","draft":false,"unlisted":false,"editUrl":"https://github.com/wailsapp/wails/edit/master/website/versioned_docs/version-v2.13.0/reference/menus.mdx","tags":[],"version":"v2.13.0","sidebarPosition":4,"frontMatter":{"sidebar_position":4},"sidebar":"docs","previous":{"title":"Options","permalink":"/docs/v2.13.0/reference/options"},"next":{"title":"Project Config","permalink":"/docs/v2.13.0/reference/project-config"}}');var l=t(74848),s=t(28453);const r={sidebar_position:4},c="Menus",d={},a=[{value:"Menu",id:"menu",level:2},{value:"MenuItem",id:"menuitem",level:2},{value:"Accelerator",id:"accelerator",level:3},{value:"Modifier",id:"modifier",level:4},{value:"Type",id:"type",level:3},{value:"Callback",id:"callback",level:3},{value:"Role",id:"role",level:3}];function o(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.header,{children:(0,l.jsx)(n.h1,{id:"menus",children:"Menus"})}),"\n",(0,l.jsxs)(n.p,{children:["It is possible to add an application menu to Wails projects. This is achieved by defining a ",(0,l.jsx)(n.a,{href:"#menu",children:"Menu"})," struct and\nsetting it in the ",(0,l.jsx)(n.a,{href:"/docs/v2.13.0/reference/options#menu",children:(0,l.jsx)(n.code,{children:"Menu"})})," application config, or by calling the runtime method\n",(0,l.jsx)(n.a,{href:"/docs/v2.13.0/reference/runtime/menu#menusetapplicationmenu",children:"MenuSetApplicationMenu"}),"."]}),"\n",(0,l.jsxs)(n.p,{children:["An example of how to create a menu, using ",(0,l.jsxs)(n.a,{href:"/docs/v2.13.0/guides/application-development",children:["the ",(0,l.jsx)(n.code,{children:"NewApp"})," scaffold"]}),":"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="main.go"',children:'package main\n\nimport (\n    "log"\n    "runtime"\n\n    "github.com/wailsapp/wails/v2"\n    "github.com/wailsapp/wails/v2/pkg/menu"\n    "github.com/wailsapp/wails/v2/pkg/menu/keys"\n    "github.com/wailsapp/wails/v2/pkg/options"\n    rt "github.com/wailsapp/wails/v2/pkg/runtime"\n)\n\nfunc main() {\n    app := NewApp()\n\n    AppMenu := menu.NewMenu()\n    if runtime.GOOS == "darwin" {\n        AppMenu.Append(menu.AppMenu()) // On macOS platform, this must be done right after `NewMenu()`\n    }\n    FileMenu := AppMenu.AddSubmenu("File")\n    FileMenu.AddText("&Open", keys.CmdOrCtrl("o"), func(_ *menu.CallbackData) {\n        // do something\n    })\n    FileMenu.AddSeparator()\n    FileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {\n        // `rt` is an alias of "github.com/wailsapp/wails/v2/pkg/runtime" to prevent collision with standard package\n        rt.Quit(app.ctx)\n    })\n\n    if runtime.GOOS == "darwin" {\n        AppMenu.Append(menu.EditMenu())  // On macOS platform, EditMenu should be appended to enable Cmd+C, Cmd+V, Cmd+Z... shortcuts\n    }\n\n    err := wails.Run(&options.App{\n        Title:             "Menus Demo",\n        Width:             800,\n        Height:            600,\n        Menu:              AppMenu, // reference the menu above\n        Bind: []interface{}{\n            app,\n        },\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n'})}),"\n",(0,l.jsxs)(n.p,{children:["It is also possible to dynamically update the menu, by updating the menu struct and calling\n",(0,l.jsx)(n.a,{href:"/docs/v2.13.0/reference/runtime/menu#menuupdateapplicationmenu",children:"MenuUpdateApplicationMenu"}),"."]}),"\n",(0,l.jsx)(n.p,{children:"The example above uses helper methods, however it's possible to build the menu structs manually."}),"\n",(0,l.jsx)(n.h2,{id:"menu",children:"Menu"}),"\n",(0,l.jsx)(n.p,{children:"A Menu is a collection of MenuItems:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu"',children:"type Menu struct {\n\tItems []*MenuItem\n}\n"})}),"\n",(0,l.jsx)(n.p,{children:'For the Application menu, each MenuItem represents a single menu such as "Edit".'}),"\n",(0,l.jsx)(n.p,{children:"A simple helper method is provided for building menus:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu"',children:"func NewMenuFromItems(first *MenuItem, rest ...*MenuItem) *Menu\n"})}),"\n",(0,l.jsx)(n.p,{children:"This makes the layout of the code more like that of a menu without the need to add the menu items manually after creating them.\nAlternatively, you can just create the menu items and add them to the menu manually."}),"\n",(0,l.jsx)(n.h2,{id:"menuitem",children:"MenuItem"}),"\n",(0,l.jsx)(n.p,{children:"A MenuItem represents an item within a Menu."}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu"',children:"// MenuItem represents a menu item contained in a menu\ntype MenuItem struct {\n\tLabel string\n\tRole Role\n\tAccelerator *keys.Accelerator\n\tType Type\n\tDisabled bool\n\tHidden bool\n\tChecked bool\n\tSubMenu *Menu\n\tClick Callback\n}\n"})}),"\n",(0,l.jsxs)(n.table,{children:[(0,l.jsx)(n.thead,{children:(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.th,{children:"Field"}),(0,l.jsx)(n.th,{children:"Type"}),(0,l.jsx)(n.th,{children:"Notes"})]})}),(0,l.jsxs)(n.tbody,{children:[(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Label"}),(0,l.jsx)(n.td,{children:"string"}),(0,l.jsx)(n.td,{children:"The menu text"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Accelerator"}),(0,l.jsx)(n.td,{children:(0,l.jsx)(n.a,{href:"#accelerator",children:"*keys.Accelerator"})}),(0,l.jsx)(n.td,{children:"Key binding for this menu item"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Type"}),(0,l.jsx)(n.td,{children:(0,l.jsx)(n.a,{href:"#type",children:"Type"})}),(0,l.jsx)(n.td,{children:"Type of MenuItem"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Disabled"}),(0,l.jsx)(n.td,{children:"bool"}),(0,l.jsx)(n.td,{children:"Disables the menu item"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Hidden"}),(0,l.jsx)(n.td,{children:"bool"}),(0,l.jsx)(n.td,{children:"Hides this menu item"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Checked"}),(0,l.jsx)(n.td,{children:"bool"}),(0,l.jsx)(n.td,{children:"Adds check to item (Checkbox & Radio types)"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"SubMenu"}),(0,l.jsx)(n.td,{children:(0,l.jsx)(n.a,{href:"#menu",children:"*Menu"})}),(0,l.jsx)(n.td,{children:"Sets the submenu"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Click"}),(0,l.jsx)(n.td,{children:(0,l.jsx)(n.a,{href:"#callback",children:"Callback"})}),(0,l.jsx)(n.td,{children:"Callback function when menu clicked"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"Role"}),(0,l.jsx)(n.td,{children:"string"}),(0,l.jsxs)(n.td,{children:["Defines a ",(0,l.jsx)(n.a,{href:"#role",children:"role"})," for this menu item. Mac only for now."]})]})]})]}),"\n",(0,l.jsx)(n.h3,{id:"accelerator",children:"Accelerator"}),"\n",(0,l.jsxs)(n.p,{children:["Accelerators (sometimes called keyboard shortcuts) define a binding between a keystroke and a menu item. Wails defines\nan Accelerator as a combination or key + ",(0,l.jsx)(n.a,{href:"#modifier",children:"Modifier"}),". They are available in the ",(0,l.jsx)(n.code,{children:'"github.com/wailsapp/wails/v2/pkg/menu/keys"'})," package."]}),"\n",(0,l.jsx)(n.p,{children:"Example:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu/keys"',children:'    // Defines cmd+o on Mac and ctrl-o on Window/Linux\n    myShortcut := keys.CmdOrCtrl("o")\n'})}),"\n",(0,l.jsxs)(n.p,{children:["Keys are any single character on a keyboard with the exception of ",(0,l.jsx)(n.code,{children:"+"}),", which is defined as ",(0,l.jsx)(n.code,{children:"plus"}),".\nSome keys cannot be represented as characters so there are a set of named characters that may be used:"]}),"\n",(0,l.jsxs)(n.table,{children:[(0,l.jsx)(n.thead,{children:(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.th,{style:{textAlign:"center"}}),(0,l.jsx)(n.th,{style:{textAlign:"center"}}),(0,l.jsx)(n.th,{style:{textAlign:"center"}}),(0,l.jsx)(n.th,{style:{textAlign:"center"}})]})}),(0,l.jsxs)(n.tbody,{children:[(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"backspace"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f1"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f16"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f31"})})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"tab"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f2"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f17"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f32"})})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"return"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f3"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f18"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f33"})})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"enter"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f4"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f19"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f34"})})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"escape"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f5"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f20"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f35"})})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"left"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f6"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f21"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"numlock"})})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"right"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f7"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f22"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"up"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f8"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f23"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"down"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f9"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f24"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"space"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f10"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f25"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"delete"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f11"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f36"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"home"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f12"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f37"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"end"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f13"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f38"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"page up"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f14"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f39"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"page down"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f15"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"},children:(0,l.jsx)(n.code,{children:"f30"})}),(0,l.jsx)(n.td,{style:{textAlign:"center"}})]})]})]}),"\n",(0,l.jsx)(n.p,{children:"Wails also supports parsing accelerators using the same syntax as Electron. This is useful for storing accelerators in\nconfig files."}),"\n",(0,l.jsx)(n.p,{children:"Example:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu/keys"',children:'    // Defines cmd+o on Mac and ctrl-o on Window/Linux\n    myShortcut, err := keys.Parse("Ctrl+Option+A")\n'})}),"\n",(0,l.jsx)(n.h4,{id:"modifier",children:"Modifier"}),"\n",(0,l.jsx)(n.p,{children:"The following modifiers are keys that may be used in combination with the accelerator key:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu/keys"',children:'const (\n\t// CmdOrCtrlKey represents Command on Mac and Control on other platforms\n\tCmdOrCtrlKey Modifier = "cmdorctrl"\n\t// OptionOrAltKey represents Option on Mac and Alt on other platforms\n\tOptionOrAltKey Modifier = "optionoralt"\n\t// ShiftKey represents the shift key on all systems\n\tShiftKey Modifier = "shift"\n\t// ControlKey represents the control key on all systems\n\tControlKey Modifier = "ctrl"\n)\n'})}),"\n",(0,l.jsx)(n.p,{children:"A number of helper methods are available to create Accelerators using modifiers:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/w
1ailsapp/wails/v2/pkg/menu/keys"',children:"func CmdOrCtrl(key string) *Accelerator\nfunc OptionOrAlt(key string) *Accelerator\nfunc Shift(key string) *Accelerator\nfunc Control(key string) *Accelerator\n"})}),"\n",(0,l.jsxs)(n.p,{children:["Modifiers can be combined using ",(0,l.jsx)(n.code,{children:"keys.Combo(key string, modifier1 Modifier, modifier2 Modifier, rest ...Modifier)"}),":"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu/keys"',children:'    // Defines "Ctrl+Option+A" on Mac and "Ctrl+Alt+A" on Window/Linux\n    myShortcut := keys.Combo("a", ControlKey, OptionOrAltKey)\n'})}),"\n",(0,l.jsx)(n.h3,{id:"type",children:"Type"}),"\n",(0,l.jsx)(n.p,{children:"Each menu item must have a type and there are 5 types available:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu"',children:'const (\n\tTextType Type = "Text"\n\tSeparatorType Type = "Separator"\n\tSubmenuType Type = "Submenu"\n\tCheckboxType Type = "Checkbox"\n\tRadioType Type = "Radio"\n)\n'})}),"\n",(0,l.jsx)(n.p,{children:"For convenience, helper methods are provided to quickly create a menu item:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu"',children:"func Text(label string, accelerator *keys.Accelerator, click Callback) *MenuItem\nfunc Separator() *MenuItem\nfunc Radio(label string, selected bool, accelerator *keys.Accelerator, click Callback) *MenuItem\nfunc Checkbox(label string, checked bool, accelerator *keys.Accelerator, click Callback) *MenuItem\nfunc SubMenu(label string, menu *Menu) *Menu\n"})}),"\n",(0,l.jsx)(n.p,{children:'You can also create menu items directly on a menu by using the "Add" helpers:'}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu"',children:"func (m *Menu) AddText(label string, accelerator *keys.Accelerator, click Callback) *MenuItem\nfunc (m *Menu) AddSeparator() *MenuItem\nfunc (m *Menu) AddRadio(label string, selected bool, accelerator *keys.Accelerator, click Callback) *MenuItem\nfunc (m *Menu) AddCheckbox(label string, checked bool, accelerator *keys.Accelerator, click Callback) *MenuItem\nfunc (m *Menu) AddSubMenu(label string, menu *Menu) *MenuI\n"})}),"\n",(0,l.jsx)(n.p,{children:"A note on radio groups: A radio group is defined as a number of radio menu items that are next to each other in the menu.\nThis means that you do not need to group items together as it is automatic. However, that also means you cannot have 2\nradio groups next to each other - there must be a non-radio item between them."}),"\n",(0,l.jsx)(n.h3,{id:"callback",children:"Callback"}),"\n",(0,l.jsx)(n.p,{children:"Each menu item may have a callback that is executed when the item is clicked:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-go",metastring:'title="Package: github.com/wailsapp/wails/v2/pkg/menu"',children:"type Callback func(*CallbackData)\n\ntype CallbackData struct {\n\tMenuItem    *MenuItem\n}\n"})}),"\n",(0,l.jsxs)(n.p,{children:["The function is given a ",(0,l.jsx)(n.code,{children:"CallbackData"})," struct which indicates which menu item triggered the callback. This is useful when\nusing radio groups that may share a callback."]}),"\n",(0,l.jsx)(n.h3,{id:"role",children:"Role"}),"\n",(0,l.jsx)(n.admonition,{title:"Roles",type:"info",children:(0,l.jsx)(n.p,{children:"Roles are currently supported on Mac only."})}),"\n",(0,l.jsx)(n.p,{children:"A menu item may have a role, which is essentially a pre-defined menu item. We currently support the following roles:"}),"\n",(0,l.jsxs)(n.table,{children:[(0,l.jsx)(n.thead,{children:(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.th,{children:"Role"}),(0,l.jsx)(n.th,{children:"Description"})]})}),(0,l.jsxs)(n.tbody,{children:[(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"AppMenuRole"}),(0,l.jsxs)(n.td,{children:["The standard Mac application menu. Can be created using ",(0,l.jsx)(n.code,{children:"menu.AppMenu()"})]})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"EditMenuRole"}),(0,l.jsxs)(n.td,{children:["The standard Mac edit menu. Can be created using ",(0,l.jsx)(n.code,{children:"menu.EditMenu()"})]})]})]})]})]})}function h(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(o,{...e})}):o(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.