Files
8bitMyGoUI/display/avatargroup.go
T
ZacharyZhang-NY 1f3d38110e One component per file; GAME OVER offers CONTINUE
PRD G1 asks for one component per file. Eight files held two or
three; their eleven extra components move to files of their own,
helpers stay where both sides use them, and an archtest now fails
any file that holds two.

PRD 4.4 and the request say an error always offers CONTINUE.
ErrorState's button read RETRY; it now reads CONTINUE, under the
CONTINUE? countdown, on the crash screen and the lost page alike.
2026-10-12 16:50:17 -04:00

47 lines
1.1 KiB
Go

package display
import (
"strings"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type AvatarGroupOptions struct {
// Max faces shown before +N; zero means 4.
Max int
Scale int
}
// AvatarGroup overlaps faces and counts the rest in a chip.
func AvatarGroup(c *ui.Context, names []string, o AvatarGroupOptions) *ui.Element {
k, sc := pixel.K(c), scale(o.Scale)
shown := names[:min(len(names), pixel.Or("AvatarGroup Max", o.Max, 4))]
rest := len(names) - len(shown)
more := ""
if rest > 0 {
more = "+" + itoa(rest)
}
step := 12 * sc
w := max(0, len(shown)-1)*step + 16*sc
if more != "" {
w += pixel.MicroWidth(more) + 8
}
return art(c, k, strings.Join(names, ", "), w, 16*sc, func(g pixel.Canvas) {
for i, name := range shown {
x := i * step
Face(g, x, 0, name, sc)
if i > 0 {
g.VLine(x, 0, 16*sc, pixel.Back)
}
}
if more != "" {
x := len(shown)*step + 4*sc
cw := pixel.MicroWidth(more) + 4
g.Frame(x, (16*sc-9)/2, cw, 9, pixel.Notched, pixel.Face)
g.Micro(x+2, (16*sc-9)/2+2, more, pixel.Ink, 1)
}
})
}