Skip to Content
Onevra

Progress

Bars and rings for work of known length, and spinners for the rest.

Loading the live example…

progress.go
import (
	"fmt"

	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type upload struct {
	done float64
}

func (u *upload) View(c *ui.Context) {
	t := c.Theme()
	ui.Column(c).Width(320).MaxWidthPercent(100).Gap(16).Children(func() {
		ui.Row(c).FillWidth().Children(func() {
			components.Text(c, "Uploading photos").Grow(1)
			components.Text(c, fmt.Sprintf("%.0f%%", u.done*100)).TextColor(t.TextMuted)
		})
		components.Progress(c, u.done)
		ui.Row(c).Gap(12).AlignItems(ui.Center).Children(func() {
			components.ProgressRing(c, u.done)
			if components.Button(c, "Advance", components.ButtonSecondary).Clicked() {
				u.done = min(1, u.done+0.2)
			}
			if components.Button(c, "Reset", components.ButtonGhost).Clicked() {
				u.done = 0
			}
		})
	})
}
Source

components.Progress and components.ProgressRing show a fraction from 0 to 1, animating as it changes.

Spinners

components.Spinner shows work of unknown length, as a ring like ProgressRing's or as fading spokes. Name it with Label. Reduced Motion freezes it.

Loading the live example…

spinner.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type busy struct{}

func (busy) View(c *ui.Context) {
	t := c.Theme()
	ui.Row(c).Gap(24).AlignItems(ui.Center).Children(func() {
		components.Spinner(c, components.SpinnerRing).Label("Loading")
		components.Spinner(c, components.SpinnerSpokes).Label("Loading")
		components.Spinner(c, components.SpinnerSpokes).Label("Syncing").TextColor(t.Accent)
	})
}
Source

API

Progress

func Progress(c *ui.Context, value float64) ui.Element

Progress creates a horizontal progress bar. Values in [0, 1] show completion; negative values show indeterminate activity. Values above 1 clamp to 1 and NaN is treated as 0. Name the indicator with Label for accessibility. The default height is theme-scaled; callers control width with layout methods.

pkg.go.dev

ProgressRing

func ProgressRing(c *ui.Context, value float64) ui.Element

ProgressRing creates a circular progress indicator with the same value semantics as Progress. Completion starts at twelve o'clock and runs clockwise. Its default diameter is theme-scaled. A custom non-square layout keeps the ring circular and centered. Reduced Motion leaves indeterminate activity static.

pkg.go.dev

Spinner

func Spinner(c *ui.Context, variant SpinnerVariant) ui.Element

Spinner creates an indicator of work of unknown length. Name it with Label for accessibility. Both variants default to a theme-scaled diameter and stay circular and centered in non-square layouts. Reduced Motion freezes activity. Spokes use the theme's muted text color unless overridden with TextColor. Unknown variants use SpinnerRing.

pkg.go.dev

SpinnerVariant

type SpinnerVariant int

SpinnerVariant selects the appearance of an indeterminate activity indicator.

const (
	// SpinnerRing uses the same track and rotating arc as ProgressRing.
	SpinnerRing SpinnerVariant = iota
	// SpinnerSpokes uses twelve fading spokes, like MyGo's built-in spinner.
	SpinnerSpokes
)
pkg.go.dev
Edit this page on GitHub

On this page