Speech bubbles, a chat log that follows its end, a composer that sends on Enter, typing dots, chat and channel lists, read receipts, reactions, emoji and sticker pickers, mentions, date and unread rules, system lines, member lists, user cards, a mailbox, mail reader and letter, a notification bell, call controls, a voice meter, attachment chips, link previews and polls. pixel's editor takes EnterSends; display's Bubble takes a Fill and exports EmojiSprite. data.List names its rows, which also lets typing choose one. layout.ScrollArea and input.TextArea hold still under Inert, and an inert scroll view leaves the Tab order until it wakes.
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)
|
|
}
|
|
})
|
|
}))
|
|
}
|