theme/cupertino/checkbox.go

Functions Structs

Functions

func PaintCheckbox

PaintCheckbox renders a checkbox as an iOS toggle switch.

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

	colors := state.ColorScheme
	if colors == (checkbox.CheckboxColorScheme{}) {
		colors = p.resolveColors()
	}

	disabled := state.Disabled
	trackRect := cupToggleTrackRect(state.Bounds)

	if state.Checked || state.Indeterminate {
		cupPaintToggleOn(canvas, trackRect, state, disabled, colors)
	} else {
		cupPaintToggleOff(canvas, trackRect, state, disabled, colors)
	}

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

	// Focus ring.
	if state.Focused && !disabled {
		cupDrawToggleFocusRing(canvas, trackRect, colors)
	}
}

Structs

type CheckboxPainter struct

CheckboxPainter renders checkboxes as iOS-style toggle switches.

Instead of the traditional square checkbox, Cupertino uses a pill-shaped

toggle switch that slides between on/off states.

 

The toggle track is a rounded pill. When checked (on), the track fills

with the accent color and the thumb knob slides to the right.

When unchecked (off), the track shows a gray outline.

 

If Theme is nil, CheckboxPainter falls back to the default system blue palette.

type CheckboxPainter struct {
	Theme *Theme	// nil uses default system blue fallback
}