theme/material3/checkbox.go

Functions Structs

Functions

func PaintCheckbox

PaintCheckbox renders a checkbox according to Material 3 specifications.

func (p CheckboxPainter) PaintCheckbox(canvas widget.Canvas, state checkbox.PaintState) {
	if state.Bounds.IsEmpty() {
		return
	}

	// Determine the color scheme to use.
	colors := state.ColorScheme
	if colors == (checkbox.CheckboxColorScheme{}) {
		colors = p.resolveColors()
	}

	boxRect := m3CheckboxBoxRect(state.Bounds)
	disabled := state.Disabled

	if state.Checked || state.Indeterminate {
		m3PaintCheckedBox(canvas, boxRect, state, disabled, colors)
	} else {
		m3PaintUncheckedBox(canvas, boxRect, state, disabled, colors)
	}

	// Draw label if present.
	if state.Label != "" {
		fg := colors.LabelColor
		if disabled {
			fg = colors.DisabledFg
		}
		labelBounds := m3CheckboxLabelBounds(state.Bounds)
		canvas.DrawText(state.Label, labelBounds, m3CheckboxFontSize, fg, false, m3CheckboxTextAlignLeft)
	}

	// Draw focus ring when focused.
	if state.Focused && !disabled {
		m3DrawCheckboxFocusIndicator(canvas, boxRect, colors)
	}
}

Structs

type CheckboxPainter struct

CheckboxPainter renders checkboxes using Material 3 design tokens.

It maps checkbox states (checked, unchecked, indeterminate) to

the M3 color scheme and applies appropriate interaction feedback.

 

If Theme is nil, CheckboxPainter falls back to the default M3 purple palette.

type CheckboxPainter struct {
	Theme *Theme	// nil uses default M3 purple fallback
}