theme/material3/progressbar.go
Functions
func PaintProgressBar
func (p ProgressBarPainter) PaintProgressBar(canvas widget.Canvas, ps progressbar.PaintState) {
if ps.Bounds.IsEmpty() {
return
}
// Determine the color scheme to use.
colors := ps.ProgressBarColorScheme
if colors == (progressbar.ProgressBarColorScheme{}) {
colors = p.resolveColors()
}
radius := ps.Radius
if radius <= 0 {
radius = m3ProgressBarRadius
}
bounds := ps.Bounds
// Calculate bar rect centered vertically in bounds.
barY := bounds.Min.Y + (bounds.Height()-ps.BarHeight)/2
barRect := geometry.NewRect(bounds.Min.X, barY, bounds.Width(), ps.BarHeight)
// Draw track.
trackColor := colors.Track
if ps.Disabled {
trackColor = colors.DisabledTrack
}
canvas.DrawRoundRect(barRect, trackColor, radius)
// Draw filled portion.
fillWidth := barRect.Width() * float32(ps.Value)
if fillWidth > 0 {
barColor := colors.Bar
if ps.Disabled {
barColor = colors.DisabledBar
}
fillRect := geometry.NewRect(barRect.Min.X, barRect.Min.Y, fillWidth, ps.BarHeight)
// Clip to the track's rounded rect so the fill never exceeds the track shape.
canvas.PushClipRoundRect(barRect, radius)
canvas.DrawRoundRect(fillRect, barColor, radius)
canvas.PopClip()
}
// Draw label if enabled.
if ps.ShowLabel && ps.Label != "" {
canvas.DrawText(ps.Label, barRect, m3ProgressBarFontSize, colors.Label, false, m3ProgressBarTextAlign)
}
}
Structs
type ProgressBarPainter struct
ProgressBarPainter renders progress bars using Material 3 design tokens.
It maps progress bar states (normal, disabled) to the M3 color scheme
with primary color for the filled bar and surface variant for the track.
If Theme is nil, ProgressBarPainter falls back to the default M3 purple palette.
type ProgressBarPainter struct {
Theme *Theme // nil uses default M3 purple fallback
}
PaintProgressBar renders a progress bar according to Material 3 specifications.