theme/material3/dropdown.go
Functions
func PaintMenu
func (p DropdownPainter) PaintMenu(canvas widget.Canvas, st *dropdown.MenuPaintState) {
if st.Bounds.IsEmpty() {
return
}
colors := st.ColorScheme
if colors == (dropdown.DropdownColorScheme{}) {
colors = p.resolveColors()
}
// Menu background with elevation shadow (M3 surface tint).
canvas.DrawRoundRect(st.Bounds, colors.MenuBg, m3DDMenuRadius)
canvas.StrokeRoundRect(st.Bounds, colors.MenuBorder, m3DDMenuRadius, m3DDBorderWidth)
// Clip to menu bounds for items.
canvas.PushClip(st.Bounds)
defer canvas.PopClip()
// Draw visible items.
endIndex := st.ScrollOffset + st.VisibleCount
if endIndex > len(st.Items) {
endIndex = len(st.Items)
}
for i := st.ScrollOffset; i < endIndex; i++ {
item := st.Items[i]
row := i - st.ScrollOffset
itemRect := geometry.Rect{
Min: geometry.Pt(st.Bounds.Min.X, st.Bounds.Min.Y+float32(row)*st.ItemHeight),
Max: geometry.Pt(st.Bounds.Max.X, st.Bounds.Min.Y+float32(row+1)*st.ItemHeight),
}
m3DDPaintMenuItem(canvas, itemRect, item, i, st.HighlightedIndex, st.SelectedIndex, colors)
}
}
func PaintTrigger
PaintTrigger renders a dropdown trigger according to Material 3 specifications.
func (p DropdownPainter) PaintTrigger(canvas widget.Canvas, st *dropdown.TriggerPaintState) {
if st.Bounds.IsEmpty() {
return
}
colors := st.ColorScheme
if colors == (dropdown.DropdownColorScheme{}) {
colors = p.resolveColors()
}
m3DDPaintTriggerBg(canvas, st, colors)
m3DDPaintTriggerBorder(canvas, st, colors)
m3DDPaintTriggerText(canvas, st, colors)
m3DDPaintTriggerChevron(canvas, st, colors)
if st.Focused && !st.Disabled {
m3DDDrawFocusIndicator(canvas, st.Bounds, colors)
}
}
Structs
type DropdownPainter struct
DropdownPainter renders dropdowns using Material 3 design tokens.
It implements the outlined dropdown variant with theme-derived colors.
If Theme is nil, DropdownPainter falls back to the default M3 purple palette.
type DropdownPainter struct {
Theme *Theme // nil uses default M3 purple fallback
}
PaintMenu renders a dropdown menu according to Material 3 specifications.