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.
This commit is contained in:
50 files changed
+2697
-34
No files matched your search
+9
-2
@@ -17,6 +17,8 @@ type EditorOptions struct {
|
||||
Placeholder string
|
||||
Label string
|
||||
Disabled bool
|
||||
// EnterSends submits a multi-line field on Enter; Shift+Enter breaks lines.
|
||||
EnterSends bool
|
||||
}
|
||||
|
||||
type Edit struct {
|
||||
@@ -33,6 +35,7 @@ type editLine struct{ start, end int }
|
||||
|
||||
type editEnv struct {
|
||||
multi bool
|
||||
sends bool
|
||||
maxLen int
|
||||
mask rune
|
||||
width int
|
||||
@@ -47,6 +50,9 @@ func Editor(c *ui.Context, value *string, o EditorOptions) Edit {
|
||||
if o.MaxLength < 0 {
|
||||
panic(fmt.Sprintf("pixel: MaxLength %d", o.MaxLength))
|
||||
}
|
||||
if o.EnterSends && !o.Multiline {
|
||||
panic("pixel: EnterSends needs a multi-line field")
|
||||
}
|
||||
shell, base, _ := Shell(c, func() *ui.Element {
|
||||
return ui.Box(c).Focusable().Role(ui.RoleTextField).Label(o.Label).Disabled(o.Disabled)
|
||||
})
|
||||
@@ -58,7 +64,7 @@ func Editor(c *ui.Context, value *string, o EditorOptions) Edit {
|
||||
base.Description(*value)
|
||||
}
|
||||
width, check := WrapWidth(c, shell)
|
||||
env := editEnv{multi: o.Multiline, maxLen: o.MaxLength, mask: o.Mask, width: width, dot: k.dot, read: c.ReadClipboard, write: c.WriteClipboard}
|
||||
env := editEnv{multi: o.Multiline, sends: o.EnterSends, maxLen: o.MaxLength, mask: o.Mask, width: width, dot: k.dot, read: c.ReadClipboard, write: c.WriteClipboard}
|
||||
shown := s.view(o.Mask, true)
|
||||
caret := s.caret + s.composeCaret
|
||||
lines := editLayout(shown, width, o.Multiline)
|
||||
@@ -403,7 +409,8 @@ func (s *editState) key(ev ui.InputEvent, e editEnv) bool {
|
||||
s.eraseOr(s.caret, s.caret+1)
|
||||
}
|
||||
case ui.KeyEnter:
|
||||
if !e.multi || m != 0 {
|
||||
brk := e.multi && m == 0 && (shift || !e.sends)
|
||||
if !brk {
|
||||
s.submitted = true
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -145,6 +145,20 @@ func TestEditorMultiline(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditorEnterSends(t *testing.T) {
|
||||
h := newEdit(t, "hi", 200, pixel.EditorOptions{Multiline: true, EnterSends: true})
|
||||
h.focus()
|
||||
h.tt.Key(ui.Shift, ui.KeyEnter)
|
||||
h.tt.Type("yo")
|
||||
h.want("hi\nyo")
|
||||
h.tt.Key(0, ui.KeyEnter)
|
||||
if h.submits != 1 {
|
||||
t.Fatalf("Enter submitted %d times", h.submits)
|
||||
}
|
||||
h.want("hi\nyo")
|
||||
mustPanic(t, "one line", func() { newEdit(t, "", 200, pixel.EditorOptions{EnterSends: true}).tt.Frame() })
|
||||
}
|
||||
|
||||
func TestEditorLimitsAndMask(t *testing.T) {
|
||||
h := newEdit(t, "", 200, pixel.EditorOptions{MaxLength: 5})
|
||||
h.focus()
|
||||
|
||||
@@ -30,6 +30,10 @@ var messages = map[Locale]map[string]string{
|
||||
"buy": "BUY", "sell": "SELL", "done": "DONE", "tracking": "TRACKING",
|
||||
"new_game": "NEW GAME", "file": "FILE %d", "press_start": "PRESS START", "continue_game": "CONTINUE", "the_end": "THE END",
|
||||
"tip": "TIP", "you_got": "YOU GOT: %s!", "unlocked": "UNLOCKED %d/%d", "rank": "RANK", "craft": "CRAFT",
|
||||
"send": "SEND ▶", "typing": "%s IS TYPING", "today": "TODAY", "new_messages": "NEW MESSAGES", "sent": "SENT", "seen": "READ",
|
||||
"from": "FROM", "subject": "SUBJECT", "date": "DATE", "faces": "FACES", "nature": "NATURE", "items": "ITEMS",
|
||||
"mute": "MUTE", "camera": "CAMERA", "hang_up": "HANG UP", "new_count": "%d NEW", "votes": "%d VOTES", "unread": "%d UNREAD",
|
||||
"day_date": "%[1]s %[2]d %[3]s", "category": "CATEGORY", "days": "SUN MON TUE WED THU FRI SAT",
|
||||
},
|
||||
Zh: {
|
||||
"ok": "确定", "cancel": "取消", "yes": "是", "no": "否", "close": "关闭",
|
||||
@@ -58,6 +62,10 @@ var messages = map[Locale]map[string]string{
|
||||
"buy": "购买", "sell": "出售", "done": "完成", "tracking": "追踪中",
|
||||
"new_game": "新游戏", "file": "存档 %d", "press_start": "按下开始", "continue_game": "继续", "the_end": "完",
|
||||
"tip": "提示", "you_got": "获得了 %s!", "unlocked": "已解锁 %d/%d", "rank": "评价", "craft": "合成",
|
||||
"send": "发送 ▶", "typing": "%s 正在输入", "today": "今天", "new_messages": "新消息", "sent": "已发送", "seen": "已读",
|
||||
"from": "发件人", "subject": "主题", "date": "日期", "faces": "表情", "nature": "万物", "items": "道具",
|
||||
"mute": "静音", "camera": "摄像头", "hang_up": "挂断", "new_count": "%d 条新", "votes": "%d 票", "unread": "%d 未读",
|
||||
"day_date": "%[4]d月%[2]d日 周%[1]s", "category": "类别", "days": "日 一 二 三 四 五 六",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user