core/dropdown/menu.go
Functions
func Children
func (m *menuWidget) Children() []widget.Widget {
return nil
}
func Draw
Draw renders the menu items.
func (m *menuWidget) 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,
SelectedIndex: m.selectedIndex,
ScrollOffset: m.scrollOffset,
VisibleCount: m.visibleCount(),
ItemHeight: m.itemHeight,
ColorScheme: m.colorScheme,
})
}
func Event
Event handles keyboard navigation, mouse hover, and mouse clicks.
func (m *menuWidget) Event(ctx widget.Context, e event.Event) bool {
switch ev := e.(type) {
case *event.KeyEvent:
return m.handleKeyEvent(ctx, ev)
case *event.MouseEvent:
return m.handleMouseEvent(ctx, ev)
case *event.WheelEvent:
return m.handleWheelEvent(ctx, ev)
default:
return false
}
}
func Layout
Layout calculates the menu size based on visible items.
func (m *menuWidget) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size {
visibleCount := m.visibleCount()
height := float32(visibleCount) * m.itemHeight
// Width matches constraints (typically matched to trigger width).
width := constraints.MaxWidth
if width >= geometry.Infinity {
width = 200 // reasonable fallback
}
preferred := geometry.Sz(width, height)
return constraints.Constrain(preferred)
}
Children returns nil; the menu is a leaf widget.