menu

package
v2.0.0-alpha.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 2 Imported by: 26

README

Menus

Menu support is heavily inspired by Electron's approach.

Features

  • Supports Text, Checkbox, Radio, Submenu and Separator
  • Radio groups are defined as any number of adjacent radio items
  • UTF-8 menu labels
  • UTF-8 menu IDs

Documentation

Overview

Package menu provides all the functions and structs related to menus in a Wails application. Heavily inspired by Electron (c) 2013-2020 Github Inc. Electron License: https://github.com/electron/electron/blob/master/LICENSE

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(*CallbackData)

type CallbackData

type CallbackData struct {
	MenuItem    *MenuItem
	ContextData string
}

type ContextMenu

type ContextMenu struct {
	ID   string
	Menu *Menu
}

func NewContextMenu

func NewContextMenu(ID string, menu *Menu) *ContextMenu
type Menu struct {
	Items []*MenuItem
}

func DefaultMacMenu

func DefaultMacMenu() *Menu

DefaultMacMenu returns a default menu including the default Application and Edit menus. Use `.Append()` to add to it.

func NewMenu

func NewMenu() *Menu

func NewMenuFromItems

func NewMenuFromItems(first *MenuItem, rest ...*MenuItem) *Menu
func (m *Menu) Append(item *MenuItem)
func (m *Menu) Merge(menu *Menu)

Merge will append the items in the given menu into this menu

func (m *Menu) Prepend(item *MenuItem)
type MenuItem struct {
	// Label is what appears as the menu text
	Label string
	// Role is a predefined menu type
	Role Role `json:"Role,omitempty"`
	// Accelerator holds a representation of a key binding
	Accelerator *keys.Accelerator `json:"Accelerator,omitempty"`
	// Type of MenuItem, EG: Checkbox, Text, Separator, Radio, Submenu
	Type Type
	// Disabled makes the item unselectable
	Disabled bool
	// Hidden ensures that the item is not shown in the menu
	Hidden bool
	// Checked indicates if the item is selected (used by Checkbox and Radio types only)
	Checked bool
	// Submenu contains a list of menu items that will be shown as a submenu
	//SubMenu []*MenuItem `json:"SubMenu,omitempty"`
	SubMenu *Menu `json:"SubMenu,omitempty"`

	// Callback function when menu clicked
	Click Callback `json:"-"`

	// Colour
	RGBA string

	// Font
	FontSize int
	FontName string

	// Image - base64 image data
	Image string

	// Tooltip
	Tooltip string
	// contains filtered or unexported fields
}

MenuItem represents a menuitem contained in a menu

func About

func About() *MenuItem

About provides a MenuItem with the About role

func AppMenu

func AppMenu() *MenuItem

AppMenu provides a MenuItem with the whole default "App" menu (About, Services, etc.)

func Checkbox

func Checkbox(label string, checked bool, accelerator *keys.Accelerator, click Callback) *MenuItem

Checkbox is a helper to create basic Checkbox menu items

func Copy

func Copy() *MenuItem

Copy provides a MenuItem with the Copy role

func Cut

func Cut() *MenuItem

Cut provides a MenuItem with the Cut role

func Delete

func Delete() *MenuItem

Delete provides a MenuItem with the Delete role

func EditMenu

func EditMenu() *MenuItem

EditMenu provides a MenuItem with the whole default "Edit" menu (Undo, Copy, etc.).

func FileMenu

func FileMenu() *MenuItem

FileMenu provides a MenuItem with the whole default "File" menu (Close / Quit)

func Front

func Front() *MenuItem

Front provides a MenuItem that maps to the arrangeInFront action.

func HelpSubMenu

func HelpSubMenu() *MenuItem

HelpSubMenu provides a MenuItem with the "Help" submenu.

func Hide

func Hide() *MenuItem

Hide provides a MenuItem that maps to the hide action.

func HideOthers

func HideOthers() *MenuItem

HideOthers provides a MenuItem that maps to the hideOtherApplications action.

func Minimize

func Minimize() *MenuItem

Minimize provides a MenuItem with the Minimize role

func Paste

func Paste() *MenuItem

Paste provides a MenuItem with the Paste role

func PasteAndMatchStyle

func PasteAndMatchStyle() *MenuItem

PasteAndMatchStyle provides a MenuItem with the PasteAndMatchStyle role

func Quit

func Quit() *MenuItem

Quit provides a MenuItem with the Quit role

func Radio

func Radio(label string, selected bool, accelerator *keys.Accelerator, click Callback) *MenuItem

Radio is a helper to create basic Radio menu items with an accelerator

func Redo

func Redo() *MenuItem

Redo provides a MenuItem with the Redo role

func SelectAll

func SelectAll() *MenuItem

SelectAll provides a MenuItem with the SelectAll role

func Separator

func Separator() *MenuItem

Separator provides a menu separator

func SubMenu(label string, menu *Menu) *MenuItem

SubMenu is a helper to create Submenus

func SubMenuWithID(label string, menu *Menu) *MenuItem

SubMenuWithID is a helper to create Submenus with an ID

func Text

func Text(label string, accelerator *keys.Accelerator, click Callback) *MenuItem

Text is a helper to create basic Text menu items

func Togglefullscreen

func Togglefullscreen() *MenuItem

Togglefullscreen provides a MenuItem with the Togglefullscreen role

func Undo

func Undo() *MenuItem

Undo provides a MenuItem with the Undo role

func Unhide

func Unhide() *MenuItem

Unhide provides a MenuItem that maps to the unhideAllApplications action.

func ViewMenu

func ViewMenu() *MenuItem

ViewMenu provides a MenuItem with the whole default "View" menu (Reload, Toggle Developer Tools, etc.)

func WindowMenu added in v2.5.0

func WindowMenu() *MenuItem

WindowMenu provides a MenuItem with the whole default "Window" menu (Minimize, Zoom, etc.).

func WindowSubMenu

func WindowSubMenu() *MenuItem

WindowSubMenu provides a MenuItem with the "Window" submenu.

func Zoom

func Zoom() *MenuItem

Zoom provides a MenuItem that maps to the performZoom action.

func (m *MenuItem) Append(item *MenuItem) bool

Append will attempt to append the given menu item to this item's submenu items. If this menu item is not a submenu, then this method will not add the item and simply return false.

func (m *MenuItem) InsertAfter(item *MenuItem) bool

InsertAfter attempts to add the given item after this item in the parent menu. If there is no parent menu (we are a top level menu) then false is returned

func (m *MenuItem) InsertBefore(item *MenuItem) bool

InsertBefore attempts to add the given item before this item in the parent menu. If there is no parent menu (we are a top level menu) then false is returned

func (m *MenuItem) Parent() *MenuItem

Parent returns the parent of the menu item. If it is a top level menu then it returns nil.

func (m *MenuItem) Prepend(item *MenuItem) bool

Prepend will attempt to prepend the given menu item to this item's submenu items. If this menu item is not a submenu, then this method will not add the item and simply return false.

func (m *MenuItem) Remove()

type Role

type Role string
const (
	AboutRole              Role = "about"
	UndoRole               Role = "undo"
	RedoRole               Role = "redo"
	CutRole                Role = "cut"
	CopyRole               Role = "copy"
	PasteRole              Role = "paste"
	PasteAndMatchStyleRole Role = "pasteAndMatchStyle"
	SelectAllRole          Role = "selectAll"
	DeleteRole             Role = "delete"
	MinimizeRole           Role = "minimize"
	QuitRole               Role = "quit"
	TogglefullscreenRole   Role = "togglefullscreen"
	FileMenuRole           Role = "fileMenu"
	EditMenuRole           Role = "editMenu"
	ViewMenuRole           Role = "viewMenu"
	WindowMenuRole         Role = "windowMenu"
	AppMenuRole            Role = "appMenu"
	HideRole               Role = "hide"
	HideOthersRole         Role = "hideOthers"
	UnhideRole             Role = "unhide"
	FrontRole              Role = "front"
	ZoomRole               Role = "zoom"
	WindowSubMenuRole      Role = "windowSubMenu"
	HelpSubMenuRole        Role = "helpSubMenu"
	SeparatorItemRole      Role = "separatorItem"
)

type TrayMenu

type TrayMenu struct {

	// Label is the text we wish to display in the tray
	Label string

	// Icon is the name of the tray icon we wish to display.
	// These are read up during build from <projectdir>/trayicons and
	// the filenames are used as IDs, minus the extension
	// EG: <projectdir>/trayicons/main.png can be referenced here with "main"
	Icon string

	// Menu is the initial menu we wish to use for the tray
	Menu *Menu
}

TrayMenu are the options

type Type

type Type string

Type of the menu item

const (
	// TextType is the text menuitem type
	TextType Type = "Text"
	// SeparatorType is the Separator menuitem type
	SeparatorType Type = "Separator"
	// SubmenuType is the Submenu menuitem type
	SubmenuType Type = "Submenu"
	// CheckboxType is the Checkbox menuitem type
	CheckboxType Type = "Checkbox"
	// RadioType is the Radio menuitem type
	RadioType Type = "Radio"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL