menu

package
v2.5.13 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 5 Imported by: 0

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

View Source
const (
	AppMenuRole    Role = 1
	EditMenuRole        = 2
	WindowMenuRole      = 3
)

These constants need to be kept in sync with `v2/internal/frontend/desktop/darwin/Role.h`

Variables

View Source
var Cols = []*Col{}/* 256 elements not displayed */

Functions

This section is empty.

Types

type Callback

type Callback func(*CallbackData)

type CallbackData

type CallbackData struct {
	MenuItem *MenuItem
}

type Col

type Col struct {
	Hex  string `json:"hex"`
	Rgb  Rgb    `json:"rgb"`
	Hsl  Hsl    `json:"hsl"`
	Name string `json:"name"`
}

type ContextMenu

type ContextMenu struct {
	ID   string
	Menu *Menu
}

func NewContextMenu

func NewContextMenu(ID string, menu *Menu) *ContextMenu

type Hsl

type Hsl struct {
	H float64 `json:"h"`
	S float64 `json:"s"`
	L float64 `json:"l"`
}
type Menu struct {
	Items []*MenuItem
}

func NewMenu

func NewMenu() *Menu

func NewMenuFromItems

func NewMenuFromItems(first *MenuItem, rest ...*MenuItem) *Menu
func (m *Menu) AddCheckbox(label string, checked bool, accelerator *keys.Accelerator, click Callback) *MenuItem

AddCheckbox adds a CheckboxMenu item to the menu

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

AddRadio adds a radio item to the menu

func (m *Menu) AddSeparator()

AddSeparator adds a separator to the menu

func (m *Menu) AddSubmenu(label string) *Menu
func (m *Menu) AddText(label string, accelerator *keys.Accelerator, click Callback) *MenuItem

AddText adds a TextMenu item to the 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
	// Accelerator holds a representation of a key binding
	Accelerator *keys.Accelerator
	// 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

	// Callback function when menu clicked
	Click Callback
	// contains filtered or unexported fields
}

MenuItem represents a menuitem contained in a menu

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 EditMenu

func EditMenu() *MenuItem

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

func Label

func Label(label string) *MenuItem

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 Separator

func Separator() *MenuItem

Separator provides a menu separator

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

SubMenu is a helper to create Submenus

func Text

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

Text is a helper to create basic Text menu items

func WindowMenu

func WindowMenu() *MenuItem

WindowMenu provides a MenuItem with the whole default "Window" menu (Minimize, Zoom, etc.). On MacOS currently all options in there won't work if the window is frameless.

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) Disable() *MenuItem
func (m *MenuItem) Enable() *MenuItem
func (m *MenuItem) Hide() *MenuItem
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) IsCheckbox() bool
func (m *MenuItem) IsRadio() bool
func (m *MenuItem) IsSeparator() bool
func (m *MenuItem) OnClick(click Callback) *MenuItem
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()
func (m *MenuItem) SetAccelerator(acc *keys.Accelerator) *MenuItem
func (m *MenuItem) SetChecked(value bool) *MenuItem
func (m *MenuItem) SetLabel(name string)
func (m *MenuItem) Show() *MenuItem

type Rgb

type Rgb struct {
	R uint8 `json:"r"`
	G uint8 `json:"g"`
	B uint8 `json:"b"`
}

type Role

type Role int

Role is a type to identify menu roles

type StyledText

type StyledText struct {
	Label string
	FgCol *Col
	BgCol *Col
	Style TextStyle
}

func ParseANSI

func ParseANSI(input string) ([]*StyledText, error)

func (*StyledText) Blinking

func (s *StyledText) Blinking() bool

func (*StyledText) Bold

func (s *StyledText) Bold() bool

func (*StyledText) Faint

func (s *StyledText) Faint() bool

func (*StyledText) Inversed

func (s *StyledText) Inversed() bool

func (*StyledText) Invisible

func (s *StyledText) Invisible() bool

func (*StyledText) Italic

func (s *StyledText) Italic() bool

func (*StyledText) Strikethrough

func (s *StyledText) Strikethrough() bool

func (*StyledText) Underlined

func (s *StyledText) Underlined() bool

type TextStyle

type TextStyle int
const (
	Bold          TextStyle = 1 << 0
	Faint         TextStyle = 1 << 1
	Italic        TextStyle = 1 << 2
	Blinking      TextStyle = 1 << 3
	Inversed      TextStyle = 1 << 4
	Invisible     TextStyle = 1 << 5
	Underlined    TextStyle = 1 << 6
	Strikethrough TextStyle = 1 << 7
)

type TrayMenu

type TrayMenu struct {

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

	// Image 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"
	// If the image is not a filename, it will be treated as base64 image data
	Image string

	// MacTemplateImage indicates that on a Mac, this image is a template image
	MacTemplateImage bool

	// Text Colour
	RGBA string

	// Font
	FontSize int
	FontName string

	// Tooltip
	Tooltip string

	// Disabled makes the item unselectable
	Disabled bool

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

	// OnOpen is called when the Menu is opened
	OnOpen func()

	// OnClose is called when the Menu is closed
	OnClose func()
}

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