core/toolbar/painter.go

Functions Structs Interfaces

Functions

func PaintButtonItem

PaintButtonItem renders a button item with icon and optional text label.

func (p DefaultPainter) PaintButtonItem(canvas widget.Canvas, state PaintButtonState) {
	if state.Bounds.IsEmpty() {
		return
	}

	// Background on hover/press (disabled items get no feedback).
	if !state.Disabled {
		bg := widget.ColorTransparent
		if state.Pressed {
			bg = defaultPressedBg
		} else if state.Hovered {
			bg = defaultHoverBg
		}
		if !bg.IsTransparent() {
			canvas.DrawRoundRect(state.Bounds, bg, defaultItemRadius)
		}
	}

	// Icon color.
	fg := defaultIconColor
	if state.Disabled {
		fg = defaultDisabledColor
	}

	// Draw icon centered in the button area.
	iconBounds := iconBoundsForItem(state.Bounds, state.ShowLabel)
	icon.Draw(canvas, state.Icon, iconBounds, fg)

	// Draw label text if ShowLabel is true.
	if state.ShowLabel && state.Label != "" {
		textBounds := textBoundsForItem(state.Bounds, iconBounds)
		canvas.DrawText(state.Label, textBounds, defaultFontSize, fg, false, widget.TextAlignLeft)
	}

	// Focus ring.
	if state.Focused && !state.Disabled {
		ringBounds := state.Bounds.Expand(focusRingOffset)
		canvas.StrokeRoundRect(ringBounds, focusRingColor, defaultItemRadius+focusRingOffset, focusRingStrokeWidth)
	}
}

func PaintSeparator

PaintSeparator renders a vertical line.

func (p DefaultPainter) PaintSeparator(canvas widget.Canvas, bounds geometry.Rect) {
	if bounds.IsEmpty() {
		return
	}
	centerX := bounds.Min.X + bounds.Width()/2
	canvas.DrawLine(
		geometry.Pt(centerX, bounds.Min.Y+separatorInset),
		geometry.Pt(centerX, bounds.Max.Y-separatorInset),
		defaultSeparatorColor, separatorStrokeWidth,
	)
}

func PaintToolbar

PaintToolbar renders a light gray background for the toolbar.

func (p DefaultPainter) PaintToolbar(canvas widget.Canvas, state PaintToolbarState) {
	if state.Bounds.IsEmpty() {
		return
	}
	canvas.DrawRect(state.Bounds, defaultToolbarBg)
}

Structs

type PaintToolbarState struct

PaintToolbarState provides the current toolbar state to the painter.

type PaintToolbarState struct {
	Bounds geometry.Rect
}

type PaintButtonState struct

PaintButtonState provides the current button item state to the painter.

type PaintButtonState struct {
	Label		string
	Icon		icon.IconData
	ShowLabel	bool
	Hovered		bool
	Pressed		bool
	Focused		bool
	Disabled	bool
	Bounds		geometry.Rect
}

type DefaultPainter struct

DefaultPainter provides a minimal fallback painter with no design system styling.

It draws simple gray buttons suitable for testing and prototyping.

type DefaultPainter struct{}

Interfaces

type Painter interface

Painter draws the visual representation of a toolbar.

Each design system (Material 3, Fluent, Cupertino) provides its own

Painter implementation to render the toolbar in its visual style.

 

If no Painter is set, the toolbar uses [DefaultPainter].

type Painter interface {
	// PaintToolbar renders the toolbar background.
	PaintToolbar(canvas widget.Canvas, state PaintToolbarState)

	// PaintButtonItem renders a single button item within the toolbar.
	PaintButtonItem(canvas widget.Canvas, state PaintButtonState)

	// PaintSeparator renders a separator item within the toolbar.
	PaintSeparator(canvas widget.Canvas, bounds geometry.Rect)
}