core/titlebar/painter.go

Functions Structs Interfaces

Functions

func DrawBackground

DrawBackground renders a dark background bar.

func (p DefaultPainter) DrawBackground(canvas widget.Canvas, bounds geometry.Rect, _ BackgroundState) {
	if bounds.IsEmpty() {
		return
	}
	canvas.DrawRect(bounds, defaultBarBg)
}

func DrawControlButton

DrawControlButton renders a minimal window control button.

func (p DefaultPainter) DrawControlButton(canvas widget.Canvas, bounds geometry.Rect, control ControlType, state ControlState) {
	if bounds.IsEmpty() {
		return
	}

	// Background on hover/press.
	bg := controlBackground(control, state)
	if !bg.IsTransparent() {
		canvas.DrawRect(bounds, bg)
	}

	// Icon color.
	fg := defaultControlFg
	if control == ControlClose && state.Hovered {
		fg = widget.ColorWhite
	}

	// Draw icon glyph.
	cx := bounds.Min.X + bounds.Width()/2
	cy := bounds.Min.Y + bounds.Height()/2

	switch control {
	case ControlMinimize:
		// Horizontal line.
		canvas.DrawLine(
			geometry.Pt(cx-defaultIconHalf, cy),
			geometry.Pt(cx+defaultIconHalf, cy),
			fg, defaultIconStroke,
		)
	case ControlMaximize:
		// Square outline.
		r := geometry.NewRect(cx-defaultIconHalf, cy-defaultIconHalf, defaultIconSize, defaultIconSize)
		canvas.StrokeRect(r, fg, defaultIconStroke)
	case ControlRestore:
		// Two overlapping squares (smaller).
		offset := float32(2)
		half := defaultIconHalf - 1
		// Back square (offset up-right).
		back := geometry.NewRect(cx-half+offset, cy-half-offset, half*2, half*2)
		canvas.StrokeRect(back, fg, defaultIconStroke)
		// Front square.
		front := geometry.NewRect(cx-half, cy-half, half*2, half*2)
		canvas.DrawRect(front, defaultBarBg)	// Fill to cover back square overlap.
		canvas.StrokeRect(front, fg, defaultIconStroke)
	case ControlClose:
		// X shape via two lines.
		canvas.DrawLine(
			geometry.Pt(cx-defaultIconHalf, cy-defaultIconHalf),
			geometry.Pt(cx+defaultIconHalf, cy+defaultIconHalf),
			fg, defaultCloseStroke,
		)
		canvas.DrawLine(
			geometry.Pt(cx+defaultIconHalf, cy-defaultIconHalf),
			geometry.Pt(cx-defaultIconHalf, cy+defaultIconHalf),
			fg, defaultCloseStroke,
		)
	}
}

func String

String returns a human-readable name for the control type.

func (ct ControlType) String() string {
	if int(ct) < len(controlTypeNames) {
		return controlTypeNames[ct]
	}
	return "Unknown"
}

Structs

type BackgroundState struct

BackgroundState provides the current title bar background state to the painter.

type BackgroundState struct {
	// Focused indicates whether the application window has input focus.
	Focused bool
}

type ControlState struct

ControlState provides the current window control button state to the painter.

type ControlState struct {
	// Hovered indicates the mouse cursor is over the control button.
	Hovered	bool

	// Pressed indicates the mouse button is held down on the control button.
	Pressed	bool
}

type DefaultPainter struct

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

It draws a simple dark bar with basic window controls.

type DefaultPainter struct{}

Interfaces

type Painter interface

Painter draws the visual representation of a title bar.

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

Painter implementation to render the title bar in its visual style.

 

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

type Painter interface {
	// DrawBackground draws the title bar background.
	DrawBackground(canvas widget.Canvas, bounds geometry.Rect, state BackgroundState)

	// DrawControlButton draws a window control button (minimize, maximize, close).
	DrawControlButton(canvas widget.Canvas, bounds geometry.Rect, control ControlType, state ControlState)
}