Documentation
¶
Index ¶
- type Bar
- type Item
- type Menu
- func (m *Menu) CheckItem(label string, checked func() bool, action func()) *Menu
- func (m *Menu) Clear() *Menu
- func (m *Menu) Close()
- func (m *Menu) DisabledColor(c properties.Color) *Menu
- func (m *Menu) DisabledItem(label string) *Menu
- func (m *Menu) HoverColor(c properties.Color) *Menu
- func (m *Menu) IconItem(ic icon.Source, label string, action func()) *Menu
- func (m *Menu) IconSubMenu(ic icon.Source, label string, submenu *Menu) *Menu
- func (m *Menu) Item(label string, action func()) *Menu
- func (m *Menu) ItemPadding(p properties.Inset) *Menu
- func (m *Menu) LastLaidOut() uint64
- func (m *Menu) Layout(gtx layout.Context) layout.Dimensions
- func (m *Menu) OpenAt(p f32.Point)
- func (m *Menu) OpenAtClick(e elements.ClickEvent)
- func (m *Menu) OpenAtWindow(p image.Point)
- func (m *Menu) Opened() bool
- func (m *Menu) OutOfFlow()
- func (m *Menu) RadioItem(label string, selected func() bool, action func()) *Menu
- func (m *Menu) Separator() *Menu
- func (m *Menu) SeparatorColor(c properties.Color) *Menu
- func (m *Menu) Shortcut(text string) *Menu
- func (m *Menu) SubMenu(label string, submenu *Menu) *Menu
- func (m *Menu) Toggle(p f32.Point)
- func (m *Menu) Trigger(el elements.Element) elements.Element
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 (*Bar) Add ¶
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) OpenOnHover ¶
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 ¶
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 ¶
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 (*Menu) CheckItem ¶
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 (*Menu) Clear ¶
Clear removes every item, to fill the menu anew - a context menu built for what it opens on. It returns m for chaining.
func (*Menu) Close ¶
func (m *Menu) Close()
Close closes the menu, and any open submenu (recursively, in case a submenu itself has a submenu open).
func (*Menu) DisabledColor ¶
func (m *Menu) DisabledColor(c properties.Color) *Menu
DisabledColor sets the text color of DisabledItem rows. It returns m for chaining.
func (*Menu) DisabledItem ¶
DisabledItem appends a grayed-out, non-clickable item. It returns m for chaining.
func (*Menu) HoverColor ¶
func (m *Menu) HoverColor(c properties.Color) *Menu
HoverColor sets the background of the row under the pointer. It returns m for chaining.
func (*Menu) IconItem ¶
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 (*Menu) IconSubMenu ¶
IconSubMenu is SubMenu with a leading icon, so it lines up with IconItem rows. It returns m for chaining.
func (*Menu) ItemPadding ¶
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 (*Menu) LastLaidOut ¶
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 (*Menu) Layout ¶
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 (*Menu) OpenAtClick ¶
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 (*Menu) OpenAtWindow ¶
OpenAtWindow opens the menu at p, in window pixels. Elements given the menu with Context open it this way, at the pointer.
func (*Menu) OutOfFlow ¶
func (m *Menu) OutOfFlow()
OutOfFlow marks the menu as taking no space in a Box: it paints over the window; see elements.OutOfFlow.
func (*Menu) RadioItem ¶
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 (*Menu) SeparatorColor ¶
func (m *Menu) SeparatorColor(c properties.Color) *Menu
SeparatorColor sets the color of Separator lines. It returns m for chaining.
func (*Menu) Shortcut ¶
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 (*Menu) SubMenu ¶
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 (*Menu) Trigger ¶
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.