Rating
Rates something from zero to a number of stars.
Loading the live example…
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)
})
}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) *RatingControlRating 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.devRatingControl
RatingControl retains value changes separately from Element styling.
Prop
Type
Methods
func (r *RatingControl) Changed() boolChanged reports a user-driven value change, not initial clamping.