progress

package
v0.1.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package progress provides a circular progress indicator widget with determinate and indeterminate modes.

In determinate mode, the indicator shows a progress arc from 0% to 100%. In indeterminate mode, a rotating arc spins continuously to indicate ongoing activity.

Construction uses functional options for immutable configuration:

// Determinate (65% complete)
indicator := progress.New(
    progress.Value(0.65),
    progress.Size(48),
    progress.StrokeWidth(4),
    progress.ShowLabel(true),
)

// Indeterminate (spinner)
spinner := progress.New(
    progress.Indeterminate(true),
    progress.Size(32),
)

Visual Style

The visual rendering is provided by a Painter implementation. Each design system (Material 3, Fluent, Cupertino) supplies its own painter to render the indicator in the appropriate visual style.

If no painter is set, DefaultPainter is used, which draws the indicator using polyline arc approximation.

Signal Binding

The value property supports 4-level signal binding priority:

Accessibility

Circular progress indicators are display-only widgets. They do not accept focus or handle input events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultPainter

type DefaultPainter struct{}

DefaultPainter provides a minimal fallback painter with no design system styling. It draws a circular progress indicator using cubic Bézier arc strokes.

func (DefaultPainter) PaintProgress

func (p DefaultPainter) PaintProgress(canvas widget.Canvas, ps PaintState)

PaintProgress renders the circular progress indicator. In determinate mode, it draws a track circle and a progress arc. In indeterminate mode, it draws a rotating partial arc.

type Option

type Option func(*config)

Option configures a circular progress indicator during construction.

func ColorSchemeOpt

func ColorSchemeOpt(cs ProgressColorScheme) Option

ColorSchemeOpt sets the full color scheme for painting. This overrides the painter's built-in defaults.

func Disabled

func Disabled(d bool) Option

Disabled sets the indicator's disabled state.

func DisabledFn

func DisabledFn(fn func() bool) Option

DisabledFn sets a dynamic function for the disabled state. When set, this takes precedence over the static value but not over a signal set via DisabledSignal.

func DisabledReadonlySignal

func DisabledReadonlySignal(sig state.ReadonlySignal[bool]) Option

DisabledReadonlySignal binds the disabled state to a read-only signal. When set, this takes highest precedence over all other disabled sources.

func DisabledSignal

func DisabledSignal(sig state.Signal[bool]) Option

DisabledSignal binds the disabled state to a reactive signal. When set, the signal value takes precedence over both DisabledFn and Disabled but not over DisabledReadonlySignal.

func FormatLabelFn

func FormatLabelFn(fn func(float64) string) Option

FormatLabelFn sets a custom label formatting function. The function receives the current value (0.0 to 1.0) and returns the label string. If nil, the default "65%" format is used.

func Indeterminate

func Indeterminate(v bool) Option

Indeterminate sets whether the indicator shows as a spinning arc. When true, the value is ignored and the arc rotates continuously.

func IndicatorColor

func IndicatorColor(color widget.Color) Option

IndicatorColor sets the progress arc color.

func PainterOpt

func PainterOpt(p Painter) Option

PainterOpt sets the painter used to render the progress indicator. Each design system provides its own painter. If not set, DefaultPainter is used.

func ShowLabel

func ShowLabel(show bool) Option

ShowLabel enables or disables the percentage label in the center. Only applies to determinate mode.

func Size

func Size(diameter float32) Option

Size sets the indicator's diameter in logical pixels. Default is 48.

func StrokeWidth

func StrokeWidth(w float32) Option

StrokeWidth sets the arc stroke width in logical pixels. Default is 4.

func TrackColor

func TrackColor(color widget.Color) Option

TrackColor sets the background circle color.

func Value

func Value(v float64) Option

Value sets the indicator's initial static value (0.0 to 1.0). Values outside [0, 1] are clamped during rendering.

func ValueFn

func ValueFn(fn func() float64) Option

ValueFn sets a dynamic value function that is evaluated on each draw. When set, this takes precedence over the static value but not over a signal set via ValueSignal or ValueReadonlySignal.

func ValueReadonlySignal

func ValueReadonlySignal(sig state.ReadonlySignal[float64]) Option

ValueReadonlySignal binds the indicator's value to a read-only signal. This is useful for computed signals created via state.NewComputed. When set, this takes highest precedence over all other value sources.

func ValueSignal

func ValueSignal(sig state.Signal[float64]) Option

ValueSignal binds the indicator's value to a reactive signal. This is a one-way read binding: the widget reads the value from the signal. When set, the signal value takes precedence over both ValueFn and Value but not over ValueReadonlySignal.

type PaintState

type PaintState struct {
	Value          float64             // current value clamped to [0, 1] (determinate mode)
	Bounds         geometry.Rect       // total widget bounds
	Diameter       float32             // indicator diameter in logical pixels
	StrokeWidth    float32             // arc stroke width in logical pixels
	ShowLabel      bool                // whether to show percentage label (determinate only)
	Label          string              // pre-formatted label text (empty if ShowLabel is false)
	Indeterminate  bool                // true for spinner mode
	Rotation       float64             // current rotation in radians (indeterminate mode)
	AnimationPhase float64             // 0-1 sawtooth phase within one grow/shrink cycle
	Disabled       bool                // widget is disabled
	ColorScheme    ProgressColorScheme // theme-derived colors (zero = use defaults)
}

PaintState provides the current progress indicator state to the painter.

type Painter

type Painter interface {
	PaintProgress(canvas widget.Canvas, state PaintState)
}

Painter draws the visual representation of a circular progress indicator. Each design system (Material 3, Fluent, Cupertino) provides its own Painter implementation to render the indicator in its visual style.

If no Painter is set, the progress indicator uses DefaultPainter.

type ProgressColorScheme

type ProgressColorScheme struct {
	Indicator         widget.Color // progress arc color
	Track             widget.Color // background circle color
	Label             widget.Color // label text color
	DisabledIndicator widget.Color // arc color when disabled
	DisabledTrack     widget.Color // track color when disabled
	// contains filtered or unexported fields
}

ProgressColorScheme provides theme-derived colors for progress indicator painting. Zero value means the painter should use its built-in defaults.

type Widget

type Widget struct {
	widget.WidgetBase
	// contains filtered or unexported fields
}

Widget implements a circular progress indicator with determinate and indeterminate modes.

A circular progress indicator is created with New using functional options:

indicator := progress.New(
    progress.Value(0.65),
    progress.Size(48),
    progress.ShowLabel(true),
)

func New

func New(opts ...Option) *Widget

New creates a new circular progress indicator with the given options.

The returned widget is visible and enabled by default. It is not focusable because progress indicators are display-only widgets.

func (*Widget) Children

func (w *Widget) Children() []widget.Widget

Children returns nil because a progress indicator is a leaf widget.

func (*Widget) Draw

func (w *Widget) Draw(ctx widget.Context, canvas widget.Canvas)

Draw renders the circular progress indicator to the canvas.

func (*Widget) Event

func (w *Widget) Event(_ widget.Context, _ event.Event) bool

Event handles an input event. Progress indicators are display-only and always return false (events are never consumed).

func (*Widget) IsIndeterminate

func (w *Widget) IsIndeterminate() bool

IsIndeterminate returns true if the indicator is in indeterminate (spinner) mode.

func (*Widget) Layout

func (w *Widget) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size

Layout calculates the indicator's preferred size within the given constraints.

func (*Widget) Mount

func (w *Widget) Mount(ctx widget.Context)

Mount creates signal bindings for push-based invalidation. Implements widget.Lifecycle.

func (*Widget) SetValue

func (w *Widget) SetValue(v float64)

SetValue updates the indicator's static value. The value is clamped to [0, 1].

func (*Widget) Unmount

func (w *Widget) Unmount()

Unmount is called when the progress indicator is removed from the widget tree. Implements widget.Lifecycle.

func (*Widget) Value

func (w *Widget) Value() float64

Value returns the current resolved value (0 to 1).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL