Files
8bitMyGoUI/chat/letter.go
T
ZacharyZhang-NY 455f5f2a05 Add chat components 321-345; named List rows, inert scroll views
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.
2026-10-12 05:02:36 -04:00

54 lines
1.5 KiB
Go

package chat
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type LetterOptions struct {
// Signature closes the letter in Accent.
Signature string
// Width is in dots; zero means 180.
Width int
}
// Letter sets a body on parchment with a signature.
func Letter(c *ui.Context, body string, o LetterOptions) *ui.Element {
k := pixel.K(c)
w := pixel.Or("Letter Width", o.Width, 180)
if w < 40 {
panic("chat: a Letter needs 40 dots")
}
lines := pixel.Wrap(body, w-20, 0)
h := 20 + len(lines)*pixel.LineHeight
if o.Signature != "" {
h += pixel.LineHeight + 4
}
label := body
if o.Signature != "" {
label += " — " + o.Signature
}
return ui.Box(c).Role(ui.RoleText).Label(label).Size(k.D(w), k.D(h)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Rect(0, 0, w, h, pixel.Face)
// The edge darkens outward in three dither rings.
for i, level := range []int{12, 7, 3} {
g.Veil(i, i, w-2*i, 1, pixel.Shade, level)
g.Veil(i, h-1-i, w-2*i, 1, pixel.Shade, level)
g.Veil(i, i+1, 1, h-2-2*i, pixel.Shade, level)
g.Veil(w-1-i, i+1, 1, h-2-2*i, pixel.Shade, level)
}
for i, l := range lines {
g.Text(10, 10+i*pixel.LineHeight, l, pixel.Ink, 1)
}
if o.Signature == "" {
return
}
y, sw := 14+len(lines)*pixel.LineHeight, pixel.Measure(o.Signature)
g.Text(w-10-sw, y, o.Signature, pixel.Accent, 1)
g.HLine(w-12-sw, y+pixel.LineHeight-2, sw+2, pixel.Accent)
g.Dot(w-9, y+pixel.LineHeight-3, pixel.Accent)
})
}