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

60 lines
1.7 KiB
Go

package chat
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// Conversation is a ChatList row; Unread counts new lines.
type Conversation struct {
Name, Last string
Unread int
}
type ChatListResult struct {
Element ui.Element
// Submitted is Enter or a double click on a row.
Changed, Submitted bool
}
type ChatListOptions struct {
// Width and Height are dots; zeros mean 200 by 120.
Width, Height int
Disabled bool
}
// ChatList lists conversations: avatar, last line, unread badge.
func ChatList(c *ui.Context, text string, convs []Conversation, selected *int, o ChatListOptions) ChatListResult {
k := pixel.K(c)
w := pixel.Or("ChatList Width", o.Width, 200)
// Rows lose the ▶ gutter, the avatar and the badge.
room := w - 14 - 16 - 4 - 22
name := func(i int) string {
cv := convs[i]
if cv.Unread > 0 {
return fmt.Sprintf("%s: %s, "+k.Msg("unread"), cv.Name, cv.Last, cv.Unread)
}
return cv.Name + ": " + cv.Last
}
return ChatListResult(list(c, k, text, len(convs), selected, w, pixel.Or("ChatList Height", o.Height, 120), o.Disabled, name, func(i int) {
cv := convs[i]
if cv.Unread < 0 {
panic("chat: ChatList unread count is negative")
}
ui.Row(c).Gap(k.D(4)).AlignItems(ui.Center).FillWidth().Children(func() {
display.Avatar(c, cv.Name, display.AvatarOptions{})
ui.Column(c).Grow(1).Children(func() {
pixel.Text(c, line(cv.Name, room), pixel.TextOptions{})
pixel.Text(c, line(cv.Last, room), pixel.TextOptions{Slot: pixel.Faint})
})
if cv.Unread > 0 {
display.Badge(c, cv.Unread, display.BadgeOptions{})
}
})
}))
}