theme/material3/toolbar.go
Functions
func PaintButtonItem
func (p ToolbarPainter) PaintButtonItem(canvas widget.Canvas, state toolbar.PaintButtonState) {
if state.Bounds.IsEmpty() {
return
}
colors := p.resolveColors()
// Background on hover/press (disabled items get no feedback).
if !state.Disabled {
bg := widget.ColorTransparent
if state.Pressed {
bg = colors.PressedBg
} else if state.Hovered {
bg = colors.HoverBg
}
if !bg.IsTransparent() {
canvas.DrawRoundRect(state.Bounds, bg, m3ToolbarItemRadius)
}
}
// Icon color.
fg := colors.IconColor
if state.Disabled {
fg = colors.DisabledFg
}
// Draw icon centered in the button area.
iconBounds := m3ToolbarIconBounds(state.Bounds, state.ShowLabel)
icon.Draw(canvas, state.Icon, iconBounds, fg)
// Draw label text if ShowLabel is true.
if state.ShowLabel && state.Label != "" {
textBounds := m3ToolbarTextBounds(state.Bounds, iconBounds)
canvas.DrawText(state.Label, textBounds, m3ToolbarFontSize, fg, false, widget.TextAlignLeft)
}
// Focus ring.
if state.Focused && !state.Disabled {
ringBounds := state.Bounds.Expand(m3ToolbarFocusRingOffset)
canvas.StrokeRoundRect(ringBounds, colors.FocusRing, m3ToolbarItemRadius+m3ToolbarFocusRingOffset, m3ToolbarFocusRingWidth)
}
}
func PaintSeparator
PaintSeparator renders a vertical separator line using M3 outline-variant.
func (p ToolbarPainter) PaintSeparator(canvas widget.Canvas, bounds geometry.Rect) {
if bounds.IsEmpty() {
return
}
colors := p.resolveColors()
centerX := bounds.Min.X + bounds.Width()/2
canvas.DrawLine(
geometry.Pt(centerX, bounds.Min.Y+m3ToolbarSepInset),
geometry.Pt(centerX, bounds.Max.Y-m3ToolbarSepInset),
colors.SeparatorFg, m3ToolbarSepWidth,
)
}
func PaintToolbar
PaintToolbar renders the toolbar background using M3 surface color.
func (p ToolbarPainter) PaintToolbar(canvas widget.Canvas, state toolbar.PaintToolbarState) {
if state.Bounds.IsEmpty() {
return
}
colors := p.resolveColors()
canvas.DrawRect(state.Bounds, colors.Background)
}
Structs
type ToolbarPainter struct
ToolbarPainter renders toolbars using Material 3 design tokens.
It maps M3 color roles to toolbar elements: surface for background,
on-surface for icons, and primary-container for hover highlights.
If Theme is nil, ToolbarPainter falls back to the default M3 purple palette.
type ToolbarPainter struct {
Theme *Theme // nil uses default M3 purple fallback
}
PaintButtonItem renders a button item with icon and optional label using M3 colors.