theme/fluent/button.go

Functions Structs

Functions

func PaintButton

PaintButton renders a button according to Fluent Design specifications.

func (p ButtonPainter) PaintButton(canvas widget.Canvas, state button.PaintState) {
	if state.Bounds.IsEmpty() {
		return
	}

	radius := flButtonRadius
	if state.Radius != nil {
		radius = *state.Radius
	}

	colors := state.ColorScheme
	if colors == (button.ButtonColorScheme{}) {
		colors = p.resolveColors()
	}

	disabled := state.Disabled
	bg := flButtonBackground(state, disabled, colors)
	fg := flButtonForeground(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, flButtonBorderWidth)
	case button.TextOnly:
		if state.Hovered || state.Pressed {
			canvas.DrawRoundRect(state.Bounds, bg, radius)
		}
	}

	// Draw text centered.
	fontSize := flButtonFontSize(state.Size)
	canvas.DrawText(state.Text, state.Bounds, fontSize, fg, false, flTextAlignCenter)

	// Focus indicator: inner ring (Fluent style).
	if state.Focused && !disabled {
		flDrawFocusRing(canvas, state.Bounds, radius, colors.FocusRing)
	}
}

Structs

type ButtonPainter struct

ButtonPainter renders buttons using Fluent Design tokens.

It maps button variants (Filled/Accent, Outlined/Standard, TextOnly/Subtle,

Tonal) to the Fluent color scheme.

 

If Theme is nil, ButtonPainter falls back to the default Fluent Blue palette.

type ButtonPainter struct {
	Theme *Theme	// nil uses default Fluent Blue fallback
}