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.
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package chat
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type DateSeparatorOptions struct {
|
|
// Width is in dots; zero means 200.
|
|
Width int
|
|
}
|
|
|
|
// DateSeparator rules a line with TODAY, YESTERDAY or the date.
|
|
func DateSeparator(c *ui.Context, day time.Time, o DateSeparatorOptions) *ui.Element {
|
|
k := pixel.K(c)
|
|
now := k.Now()
|
|
// At midnight today becomes yesterday.
|
|
k.At(c, time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location()))
|
|
return rule(c, k, dayName(k, day.In(now.Location()), now), pixel.Or("DateSeparator Width", o.Width, 200), pixel.Faint, pixel.Edge)
|
|
}
|
|
|
|
// dayName is TODAY, YESTERDAY, or the locale's short date.
|
|
func dayName(k pixel.Kit, day, now time.Time) string {
|
|
same := func(a, b time.Time) bool { return a.Year() == b.Year() && a.YearDay() == b.YearDay() }
|
|
switch {
|
|
case same(day, now):
|
|
return k.Msg("today")
|
|
case same(day, now.AddDate(0, 0, -1)):
|
|
return k.Msg("yesterday")
|
|
}
|
|
wd, months := strings.Fields(k.Msg("days")), strings.Fields(k.Msg("months"))
|
|
return fmt.Sprintf(k.Msg("day_date"), wd[day.Weekday()], day.Day(), months[day.Month()-1], int(day.Month()))
|
|
}
|