theme/cupertino/button.go
Functions
func PaintButton
func (p ButtonPainter) PaintButton(canvas widget.Canvas, state button.PaintState) {
if state.Bounds.IsEmpty() {
return
}
radius := cupBtnDefaultRadius
if state.Radius != nil {
radius = *state.Radius
}
colors := state.ColorScheme
if colors == (button.ButtonColorScheme{}) {
colors = p.resolveColors()
}
disabled := state.Disabled
bg := cupResolvedBtnBackground(state, disabled, colors)
fg := cupResolvedBtnForeground(state.Variant, disabled, colors)
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, cupBtnOutlineStroke)
case button.TextOnly:
if state.Hovered || state.Pressed {
canvas.DrawRoundRect(state.Bounds, bg, radius)
}
}
fontSize := cupBtnFontSize(state.Size)
bold := state.Variant == button.Filled
canvas.DrawText(state.Text, state.Bounds, fontSize, fg, bold, cupBtnTextAlign)
if state.Focused && !disabled {
cupDrawBtnFocusRing(canvas, state.Bounds, radius, colors)
}
}
Structs
type ButtonPainter struct
ButtonPainter renders buttons using Apple HIG design tokens.
Cupertino buttons use rounded pill shapes with system blue fills.
Button variants map to iOS styles:
- Filled: rounded rect with accent color fill (primary CTA)
- Outlined: rounded rect with accent color border
- TextOnly: text-only button with accent color text
- Tonal: rounded rect with light accent tint fill
If Theme is nil, ButtonPainter falls back to the default system blue palette.
type ButtonPainter struct {
Theme *Theme // nil uses default system blue fallback
}
PaintButton renders a button according to Apple HIG specifications.