core/menu/menu.go
Functions
func Children
func (m *menuPanel) Children() []widget.Widget {
return nil
}
func Draw
Draw renders the menu panel.
func (m *menuPanel) Draw(ctx widget.Context, canvas widget.Canvas) {
if canvas == nil {
return
}
m.painter.PaintMenu(canvas, &MenuPaintState{
Bounds: m.Bounds(),
Items: m.items,
HighlightedIndex: m.highlightedIndex,
ItemHeight: itemHeight,
SeparatorHeight: separatorHeight,
SubMenuOpenIndex: m.subMenuIndex,
})
}
func Event
Event handles input events for the popup menu.
func (m *menuPanel) Event(ctx widget.Context, e event.Event) bool {
// Let submenu handle events first.
if m.subMenuPanel != nil {
if m.subMenuPanel.Event(ctx, e) {
return true
}
}
switch ev := e.(type) {
case *event.KeyEvent:
return m.handleKeyEvent(ctx, ev)
case *event.MouseEvent:
return m.handleMouseEvent(ctx, ev)
default:
return false
}
}
func HighlightedIndex
HighlightedIndex returns the currently highlighted item index for testing.
func (m *menuPanel) HighlightedIndex() int {
return m.highlightedIndex
}
func Layout
Layout returns the panel's preferred size.
func (m *menuPanel) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size {
return constraints.Constrain(menuSize(m.items))
}
func SubMenuIndex
SubMenuIndex returns the index of the item whose submenu is open for testing.
func (m *menuPanel) SubMenuIndex() int {
return m.subMenuIndex
}
func SubMenuPanel
SubMenuPanel returns the open submenu panel for testing.
func (m *menuPanel) SubMenuPanel() PanelState {
if m.subMenuPanel == nil {
return nil
}
return m.subMenuPanel
}
Interfaces
type PanelState interface
PanelState is the exported interface for accessing menu panel state.
This is primarily used for testing.
type PanelState interface {
widget.Widget
// Bounds returns the panel's bounding rectangle.
Bounds() geometry.Rect
// HighlightedIndex returns the currently highlighted item index (-1 for none).
HighlightedIndex() int
// SubMenuIndex returns the index of the item whose submenu is open (-1 for none).
SubMenuIndex() int
// SubMenuPanel returns the open submenu panel, or nil.
SubMenuPanel() PanelState
}
Children returns nil; the menu is a leaf widget (submenus are overlays).