Skip to Content
Onevra

Rating

Rates something from zero to a number of stars.

Loading the live example…

rating.go
import (
	"fmt"

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

type review struct {
	stars int
}

func (r *review) View(c *ui.Context) {
	ui.Column(c).Gap(8).AlignItems(ui.Center).Children(func() {
		components.Rating(c, &r.stars, 5).Label("Rating")
		text := "Not rated"
		if r.stars > 0 {
			text = fmt.Sprintf("%d of 5 stars", r.stars)
		}
		components.Text(c, text).TextColor(c.Theme().TextMuted)
	})
}
Source

Clicking the selected star clears the rating. The arrow keys, Home and End change it from the keyboard.

API

Rating

func Rating(c *ui.Context, value *int, maximum int) *RatingControl

Rating creates max stars bound to an application-owned integer. Values are clamped to [0, max]; a negative max means zero stars. A nil value is invalid. Clicking the selected star clears the rating. Arrows, Home and End operate on the focused control. Label supplies its accessible name. Keep the control to query Changed after applying Element methods. Key a parent for identity.

pkg.go.dev

RatingControl

RatingControl retains value changes separately from Element styling.

Prop

Type

Methods
func (r *RatingControl) Changed() bool

Changed reports a user-driven value change, not initial clamping.

pkg.go.dev
Edit this page on GitHub

On this page