core/dialog/painter.go
Functions
func PaintDialog
func (p DefaultPainter) PaintDialog(canvas widget.Canvas, ps PaintState) {
if ps.Bounds.IsEmpty() {
return
}
hasScheme := ps.ColorScheme != (DialogColorScheme{})
// Draw surface background.
bg := defaultSurfaceColor
if hasScheme {
bg = ps.ColorScheme.Surface
}
canvas.DrawRoundRect(ps.Bounds, bg, defaultDialogRadius)
// Draw border.
borderColor := defaultBorderColor
if hasScheme {
borderColor = ps.ColorScheme.Border
}
canvas.StrokeRoundRect(ps.Bounds, borderColor, defaultDialogRadius, defaultBorderWidth)
// Draw title.
if ps.Title != "" {
titleColor := defaultTitleColor
if hasScheme {
titleColor = ps.ColorScheme.Title
}
titleBounds := geometry.Rect{
Min: geometry.Pt(ps.Bounds.Min.X+dialogPadding, ps.Bounds.Min.Y+dialogPadding),
Max: geometry.Pt(ps.Bounds.Max.X-dialogPadding, ps.Bounds.Min.Y+dialogPadding+titleHeight),
}
canvas.DrawText(ps.Title, titleBounds, titleFontSize, titleColor, true, textAlignLeft)
}
// Draw action buttons (right-aligned).
p.paintActions(canvas, ps, hasScheme)
// Draw focus indicator.
if ps.Focused {
ringBounds := ps.Bounds.Expand(focusRingOffset)
ringRadius := defaultDialogRadius + focusRingOffset
canvas.StrokeRoundRect(ringBounds, defaultFocusRingColor, ringRadius, focusRingStrokeWidth)
}
}
Structs
type PaintState struct
PaintState provides the current dialog state to the painter.
type PaintState struct {
Title string
HasContent bool
Actions []Action
Focused bool
Bounds geometry.Rect // dialog surface bounds (not backdrop)
ColorScheme DialogColorScheme
}
type DialogColorScheme struct
DialogColorScheme provides theme-derived colors for dialog painting.
Zero value means the painter should use its built-in defaults.
type DialogColorScheme struct {
Backdrop widget.Color // backdrop color (semi-transparent)
Surface widget.Color // dialog background
Title widget.Color // title text color
Content widget.Color // content text color
Border widget.Color // dialog border (optional)
Shadow widget.Color // shadow color
ActionFg widget.Color // action button text color
ActionBg widget.Color // primary action button background
}
type DefaultPainter struct
DefaultPainter provides a minimal fallback painter with no design system styling.
It draws a simple dialog -- useful for testing and as a base reference.
type DefaultPainter struct{}
Interfaces
type Painter interface
Painter draws the visual representation of a dialog.
Each design system (Material 3, Fluent, Cupertino) provides its own
Painter implementation to render the dialog in its visual style.
If no Painter is set, the dialog uses [DefaultPainter].
type Painter interface {
PaintDialog(canvas widget.Canvas, state PaintState)
}
PaintDialog renders a minimal dialog with white surface and gray border.
If state.ColorScheme is non-zero, its colors are used instead of built-in defaults.