Elements are now pass-scoped value handles: tests that read bounds after a frame bind a ui.Handle. pixel tells frames apart by the build pass's root, since the Tester clock no longer moves on its own. Fix the regressions the upgrade brought: - Clipboard reads in input handlers go through c.Services(). - MyGo notes an overlay's opener after building it, so AutoFocus inside lost it; pixel.AutoFocus focuses through a Handle, and archtest bans the raw call. Dialogs hand the focus back again. - Elements around a press stay hovered: Tooltip tells a press-given focus by focus arriving under the pointer. - The web host moves the Tester clock with real time, at most 500 ms a call, and gives components the real clock. The gallery's source index also accepts CRLF checkouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
47 lines
1.1 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|