menu

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {
	// contains filtered or unexported fields
}

Bar is a menu bar: a row of menus (File, Edit, View) that behaves as one. A click on a trigger opens its menu; once one is open, moving the pointer onto another trigger switches to that menu, as does a click on it or Left and Right on the keyboard. With OpenOnHover, resting the pointer on a trigger opens its menu with none open too.

bar := menu.NewBar()
titleBar.Leading(
	bar.Add(fileMenu, fileButton),
	bar.Add(editMenu, editButton),
	bar.Add(viewMenu, viewButton),
)

Each menu must still be laid out somewhere, as with Trigger.

func NewBar

func NewBar() *Bar

NewBar returns an empty menu bar.

func (*Bar) Add

func (b *Bar) Add(m *Menu, el elements.Element) elements.Element

Add puts m in the bar and returns its trigger: el, which toggles m when clicked and switches to m while another of the bar's menus is open. Lay it out where el would go.

func (*Bar) Open

func (b *Bar) Open() *Menu

Open returns the bar's open menu, or nil.

func (*Bar) OpenOnHover

func (b *Bar) OpenOnHover(on bool) *Bar

OpenOnHover makes resting the pointer on a trigger open its menu, without a click. The menu stays open until something is chosen, a click lands outside it, Escape, or the pointer moves to another trigger. It returns b for chaining.

type Item

type Item struct {
	// contains filtered or unexported fields
}

Item is a single row of a menu.

type Menu struct {
	// contains filtered or unexported fields
}

Menu is a stateful context menu. Register it with App.SetContextMenu to open it with a right-click anywhere in the window, call OpenAt/Toggle directly, or wrap a trigger element with Trigger for a click-to-open dropdown menu.

When SetContextMenu is used the app registers the right-click area and renders the menu on top automatically; otherwise lay Menu out anywhere in the view (its panel renders via elements.RegisterPortal, so it paints above everything else regardless of tree position).

func New

func New(st ...styles.Styles) *Menu

New returns an empty menu. The styles argument is optional: Background, BorderRadius, BorderWidth, BorderColor, BoxShadow, Padding and Color (item text) are honored; the rest fall back to defaults. Menus have a 1dp theme.border border and a soft shadow, so they stand out over panels of their own color; set BorderColor to "transparent" or a BoxShadow with a transparent Color to drop them.

func (m *Menu) CheckItem(label string, checked func() bool, action func()) *Menu

CheckItem appends an item showing a check mark while checked reports true - the state lives in the app and is read every frame. action runs on click; it's up to it to flip the state. It returns m for chaining.

func (m *Menu) Clear() *Menu

Clear removes every item, to fill the menu anew - a context menu built for what it opens on. It returns m for chaining.

func (m *Menu) Close()

Close closes the menu, and any open submenu (recursively, in case a submenu itself has a submenu open).

func (m *Menu) DisabledColor(c properties.Color) *Menu

DisabledColor sets the text color of DisabledItem rows. It returns m for chaining.

func (m *Menu) DisabledItem(label string) *Menu

DisabledItem appends a grayed-out, non-clickable item. It returns m for chaining.

func (m *Menu) HoverColor(c properties.Color) *Menu

HoverColor sets the background of the row under the pointer. It returns m for chaining.

func (m *Menu) IconItem(ic icon.Source, label string, action func()) *Menu

IconItem appends an item with a leading icon - any icon.Source: a loaded SVG document, a registered icon (icon.Lookup) or path data (icon.Path). It returns m for chaining.

func (m *Menu) IconSubMenu(ic icon.Source, label string, submenu *Menu) *Menu

IconSubMenu is SubMenu with a leading icon, so it lines up with IconItem rows. It returns m for chaining.

func (m *Menu) Item(label string, action func()) *Menu

Item appends a clickable item. It returns m for chaining.

func (m *Menu) ItemPadding(p properties.Inset) *Menu

ItemPadding sets the padding of every row, in dp, replacing the default of 28 horizontal and 8 vertical. A submenu has its own setting. It returns m for chaining.

func (m *Menu) LastLaidOut() uint64

LastLaidOut is the frame (elements.FrameNumber) the menu was last laid out open in: the frame doesn't lay out an element's context menu again when the view already did.

func (m *Menu) Layout(gtx layout.Context) layout.Dimensions

Layout renders the open menu: a window-wide dismissal layer, plus the panel itself queued as a portal (see elements.RegisterPortalAt) so it paints above everything else regardless of where Layout is called from. It takes no space where it's laid out. A submenu (see SubMenu) skips the dismissal layer - its own parent row's hover state controls it instead.

func (m *Menu) OpenAt(p f32.Point)

OpenAt opens the menu anchored at p, in window pixel coordinates.

func (m *Menu) OpenAtClick(e elements.ClickEvent)

OpenAtClick opens the menu where e happened: at the pointer for a right-click or a long-press, below the clicked element for Enter or Space on it. A row or a tab opens its context menu with it:

tab.OnSecondaryClick(menu.OpenAtClick).OnLongPress(menu.OpenAtClick)
func (m *Menu) OpenAtWindow(p image.Point)

OpenAtWindow opens the menu at p, in window pixels. Elements given the menu with Context open it this way, at the pointer.

func (m *Menu) Opened() bool

Opened reports whether the menu is open.

func (m *Menu) OutOfFlow()

OutOfFlow marks the menu as taking no space in a Box: it paints over the window; see elements.OutOfFlow.

func (m *Menu) RadioItem(label string, selected func() bool, action func()) *Menu

RadioItem appends an item showing a dot while selected reports true: one of a group of choices (a playback speed, an audio track), where each item's action selects it. It returns m for chaining.

func (m *Menu) Separator() *Menu

Separator appends a horizontal line. It returns m for chaining.

func (m *Menu) SeparatorColor(c properties.Color) *Menu

SeparatorColor sets the color of Separator lines. It returns m for chaining.

func (m *Menu) Shortcut(text string) *Menu

Shortcut sets the keyboard shortcut shown right-aligned on the last item added: m.Item("Open File…", open).Shortcut("Mod+O"). A spec the shortcut package parses shows the way the platform writes it ("⌘O" on macOS, "Ctrl+O" elsewhere); other text shows as it is. It only shows the shortcut: register the key with giode.Shortcuts. It returns m for chaining.

func (m *Menu) SubMenu(label string, submenu *Menu) *Menu

SubMenu appends an item that reveals submenu as a nested panel, cascading to the side, when hovered. submenu is a *Menu of its own - built the same way as any other (Item, IconItem, Separator, SubMenu for further nesting) - but must not be registered with SetContextMenu, OpenAt, Toggle or Trigger itself: this item's hover state is its only way of opening. It returns m for chaining.

func (m *Menu) Toggle(p f32.Point)

Toggle flips the menu state, anchored at p.

func (m *Menu) Trigger(el elements.Element) elements.Element

Trigger wraps el so clicking it toggles the menu, anchored just below it - a widget-anchored, dropdown-style trigger, alongside SetContextMenu (right-click anywhere) and OpenAt/Toggle (any other custom trigger, e.g. a long-press).

The returned element must be laid out somewhere in the view like el would be on its own; m itself must also still be laid out somewhere in the tree (its panel renders via elements.RegisterPortal regardless of where) for its open state to actually render.

Jump to

Keyboard shortcuts

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