Files
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
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>
2026-10-17 01:31:08 -04:00

64 lines
1.8 KiB
Go

package chat
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type UserCardOptions struct {
Title string
Status display.Status
// Actions label the buttons along the bottom.
Actions []string
// Width is in dots; zero means 160.
Width int
Disabled bool
}
type UserCardResult struct {
Element ui.Element
// Clicked is the action clicked this frame, else -1.
Clicked int
}
// UserCard shows an avatar, name, title and action buttons.
func UserCard(c *ui.Context, name string, o UserCardOptions) UserCardResult {
k := pixel.K(c)
w := pixel.Or("UserCard Width", o.Width, 160)
res := UserCardResult{Clicked: -1}
res.Element = ui.Column(c).Width(k.D(w)).Padding(k.D(6)).Gap(k.D(5)).Role(ui.RoleGroup).Label(name).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Frame(0, 0, g.W, g.H, pixel.Window, pixel.Face)
}).Children(func() {
ui.Row(c).Gap(k.D(6)).AlignItems(ui.Center).Children(func() {
display.Avatar(c, name, display.AvatarOptions{Scale: 2})
ui.Column(c).Gap(k.D(1)).Children(func() {
ui.Row(c).Gap(k.D(3)).AlignItems(ui.Center).Children(func() {
pixel.Text(c, line(name, w-62), pixel.TextOptions{})
display.StatusDot(c, o.Status, display.StatusDotOptions{})
})
if o.Title != "" {
pixel.Text(c, line(o.Title, w-50), pixel.TextOptions{Slot: pixel.Faint})
}
})
})
if len(o.Actions) == 0 {
return
}
ui.Row(c).Gap(k.D(3)).FocusGroup(ui.Horizontal).Children(func() {
for i, a := range o.Actions {
if input.Button(c, a, input.ButtonOptions{Size: input.Small, Disabled: o.Disabled}).Clicked {
res.Clicked = i
slog.Debug("8bit: usercard action", "name", name, "action", a)
}
}
})
})
return res
}