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>
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package chat
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Channel is a # channel; Unread marks new messages.
|
|
type Channel struct {
|
|
Name string
|
|
Unread bool
|
|
}
|
|
|
|
type ChannelListResult struct {
|
|
Element ui.Element
|
|
// Submitted is Enter or a double click on a row.
|
|
Changed, Submitted bool
|
|
}
|
|
|
|
type ChannelListOptions struct {
|
|
// Width and Height are dots; zeros mean 140 by 120.
|
|
Width, Height int
|
|
Disabled bool
|
|
}
|
|
|
|
// ChannelList lists # channels; unread ones glow with a dot.
|
|
func ChannelList(c *ui.Context, text string, chans []Channel, selected *int, o ChannelListOptions) ChannelListResult {
|
|
k := pixel.K(c)
|
|
w := pixel.Or("ChannelList Width", o.Width, 140)
|
|
room := w - 14 - 8 - 10
|
|
name := func(i int) string {
|
|
if chans[i].Unread {
|
|
return chans[i].Name + ", " + k.Msg("new_messages")
|
|
}
|
|
return chans[i].Name
|
|
}
|
|
return ChannelListResult(list(c, k, text, len(chans), selected, w, pixel.Or("ChannelList Height", o.Height, 120), o.Disabled, name, func(i int) {
|
|
ch := chans[i]
|
|
ink := pixel.Faint
|
|
if ch.Unread {
|
|
ink = pixel.Ink
|
|
}
|
|
name := "# " + line(ch.Name, room)
|
|
ui.Box(c).FillWidth().Height(k.D(pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Text(0, 0, name, ink, 1)
|
|
if ch.Unread {
|
|
g.Disc(g.W-5, pixel.LineHeight/2, 2, pixel.Accent)
|
|
}
|
|
})
|
|
}))
|
|
}
|