theme/material3/button.go
Functions
func PaintButton
func (p ButtonPainter) PaintButton(canvas widget.Canvas, state button.PaintState) {
if state.Bounds.IsEmpty() {
return
}
radius := m3DefaultRadius
if state.Radius != nil {
radius = *state.Radius
}
// Determine the color scheme to use.
colors := state.ColorScheme
if colors == (button.ButtonColorScheme{}) {
colors = p.resolveColors()
}
disabled := state.Disabled
bg := m3ResolvedBackground(state, disabled, colors)
fg := m3ResolvedForeground(state.Variant, disabled, colors)
// Draw background based on variant.
switch state.Variant {
case button.Filled, button.Tonal:
canvas.DrawRoundRect(state.Bounds, bg, radius)
case button.Outlined:
if state.Hovered || state.Pressed {
canvas.DrawRoundRect(state.Bounds, colors.Primary.WithAlpha(0.08), radius)
}
canvas.StrokeRoundRect(state.Bounds, bg, radius, m3OutlineStrokeWidth)
case button.TextOnly:
if state.Hovered || state.Pressed {
canvas.DrawRoundRect(state.Bounds, bg, radius)
}
}
// Draw text centered in bounds.
fontSize := m3FontSize(state.Size)
bold := state.Variant == button.Filled
canvas.DrawText(state.Text, state.Bounds, fontSize, fg, bold, m3TextAlignCenter)
// Draw focus ring when focused.
if state.Focused && !disabled {
m3DrawFocusIndicator(canvas, state.Bounds, radius, colors)
}
}
Structs
type ButtonPainter struct
ButtonPainter renders buttons using Material 3 design tokens.
It maps button variants (Filled, Outlined, TextOnly, Tonal) to
the M3 color scheme and applies appropriate interaction feedback.
If Theme is nil, ButtonPainter falls back to the default M3 purple palette.
type ButtonPainter struct {
Theme *Theme // nil uses default M3 purple fallback
}
PaintButton renders a button according to Material 3 specifications.