theme/material3/datatable.go
Functions
func PaintCell
func (p DataTablePainter) PaintCell(canvas widget.Canvas, cps datatable.CellPaintState) {
if cps.Bounds.IsEmpty() {
return
}
colors := p.effectiveCellColors(cps.ColorScheme)
fg := colors.CellText
if cps.Disabled {
fg = fg.WithAlpha(m3TableDisabledAlpha)
}
textBounds := geometry.NewRect(
cps.Bounds.Min.X+m3TableCellPaddingH,
cps.Bounds.Min.Y,
cps.Bounds.Width()-m3TableCellPaddingH*2,
cps.Bounds.Height(),
)
canvas.DrawText(cps.Value, textBounds, m3TableCellFontSize, fg, false, cps.Align)
}
func PaintEmptyState
PaintEmptyState draws a centered "No data" message with M3 on-surface-variant color.
func (p DataTablePainter) PaintEmptyState(canvas widget.Canvas, bounds geometry.Rect) {
if bounds.IsEmpty() {
return
}
colors := p.resolveColors()
canvas.DrawText(m3TableEmptyText, bounds, m3TableEmptyFontSize, colors.EmptyText, false, widget.TextAlignCenter)
}
func PaintHeader
PaintHeader draws the table header background with M3 surface-container color.
func (p DataTablePainter) PaintHeader(canvas widget.Canvas, bounds geometry.Rect, hps datatable.HeaderPaintState) {
if bounds.IsEmpty() {
return
}
colors := p.effectiveHeaderColors(hps.ColorScheme)
canvas.DrawRect(bounds, colors.HeaderBackground)
// Bottom divider line.
dividerRect := geometry.NewRect(bounds.Min.X, bounds.Max.Y-m3TableDividerHeight, bounds.Width(), m3TableDividerHeight)
canvas.DrawRect(dividerRect, colors.Divider)
}
func PaintHeaderCell
PaintHeaderCell draws a column header with title and sort indicator.
func (p DataTablePainter) PaintHeaderCell(canvas widget.Canvas, bounds geometry.Rect, hcs datatable.HeaderCellPaintState) {
if bounds.IsEmpty() {
return
}
colors := p.effectiveHeaderCellColors(hcs.ColorScheme)
// Highlight on hover for sortable columns.
if hcs.Hovered && hcs.Sortable && !hcs.Disabled {
canvas.DrawRect(bounds, colors.HoverColor)
}
// Build display text with sort indicator.
displayText := hcs.Title
if indicator := hcs.SortDir.Indicator(); indicator != "" {
displayText = hcs.Title + " " + indicator
}
// Inset for text padding.
textBounds := geometry.NewRect(
bounds.Min.X+m3TableCellPaddingH,
bounds.Min.Y,
bounds.Width()-m3TableCellPaddingH*2,
bounds.Height(),
)
fg := colors.HeaderText
if hcs.Disabled {
fg = fg.WithAlpha(m3TableDisabledAlpha)
}
canvas.DrawText(displayText, textBounds, m3TableHeaderFontSize, fg, true, hcs.Align)
}
func PaintRow
PaintRow draws the row background with zebra striping and M3 selection/hover highlights.
func (p DataTablePainter) PaintRow(canvas widget.Canvas, rps datatable.RowPaintState) {
if rps.Bounds.IsEmpty() {
return
}
colors := p.effectiveRowColors(rps.ColorScheme)
// Zebra striping for alternate rows.
if rps.RowIndex%2 == 1 {
canvas.DrawRect(rps.Bounds, colors.RowAlternate)
}
// Selection highlight.
if rps.Selected {
canvas.DrawRect(rps.Bounds, colors.SelectionColor)
}
// Hover highlight (only when not selected to avoid double-tinting).
if rps.Hovered && !rps.Selected && !rps.Disabled {
canvas.DrawRect(rps.Bounds, colors.HoverColor)
}
// Focus ring.
if rps.Focused && !rps.Disabled {
canvas.StrokeRect(rps.Bounds, colors.FocusColor, m3TableFocusBorderWidth)
}
}
Structs
type DataTablePainter struct
DataTablePainter renders data tables using Material 3 design tokens.
It maps M3 color roles to table elements: surface-container for header,
on-surface for text, surface-variant for zebra striping, and primary for selection.
If Theme is nil, DataTablePainter falls back to the default M3 purple palette.
type DataTablePainter struct {
Theme *Theme // nil uses default M3 purple fallback
}
PaintCell draws a single data cell with M3 on-surface text color.