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
+21
-3
@@ -79,7 +79,7 @@ func keeps(t *testing.T, img *image.RGBA) {
|
||||
var heroes = []string{"Aria", "Brom", "Cyra", "Dax", "Eko"}
|
||||
|
||||
func party(c *ui.Context, sel *int, o data.ListOptions, changes, sent *int) {
|
||||
r := data.List(c, "Party", len(heroes), sel, o, func(i int) {
|
||||
r := data.List(c, "Party", len(heroes), sel, o, func(i int) string { return heroes[i] }, func(i int) {
|
||||
pixel.Text(c, heroes[i], pixel.TextOptions{})
|
||||
})
|
||||
if r.Changed {
|
||||
@@ -309,7 +309,7 @@ func TestListsKeepWholeDotsWhenScrolledByHalfADot(t *testing.T) {
|
||||
}
|
||||
tt := view(600, 300, newClock(), false, func(c *ui.Context) {
|
||||
ui.Row(c).Children(func() {
|
||||
data.List(c, "Rows", len(many), &sel, data.ListOptions{Height: 60}, func(i int) {
|
||||
data.List(c, "Rows", len(many), &sel, data.ListOptions{Height: 60}, func(i int) string { return many[i] }, func(i int) {
|
||||
pixel.Text(c, many[i], pixel.TextOptions{})
|
||||
}).Element.Width(100)
|
||||
data.Table(c, "Grid", []data.Column{{Title: "Row"}}, len(many), &sort, &row, data.TableOptions{Height: 60}, func(r, _ int) string { return many[r] })
|
||||
@@ -334,7 +334,7 @@ func TestOffListsIgnoreTheWheel(t *testing.T) {
|
||||
sel, sort, row, file, tile := 0, data.Sort{}, 0, "row 0", 0
|
||||
tt := view(800, 300, newClock(), inert, func(c *ui.Context) {
|
||||
ui.Row(c).Children(func() {
|
||||
data.List(c, "Rows", len(many), &sel, data.ListOptions{Height: 60, Disabled: !inert}, func(i int) {
|
||||
data.List(c, "Rows", len(many), &sel, data.ListOptions{Height: 60, Disabled: !inert}, func(i int) string { return many[i] }, func(i int) {
|
||||
pixel.Text(c, many[i], pixel.TextOptions{})
|
||||
})
|
||||
data.Table(c, "Grid", []data.Column{{Title: "Row"}}, len(many), &sort, &row, data.TableOptions{Height: 60, Disabled: !inert}, func(r, _ int) string { return many[r] })
|
||||
@@ -376,3 +376,21 @@ func TestInertInfiniteListIgnoresTheWheel(t *testing.T) {
|
||||
t.Fatalf("the wheel moved an inert list to %q; %d asks", tt.Texts(), asks)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListNamesRowsForReadersAndTyping(t *testing.T) {
|
||||
fruit := []string{"Apple", "Banana", "Cherry"}
|
||||
sel := 0
|
||||
tt := view(300, 200, newClock(), false, func(c *ui.Context) {
|
||||
data.List(c, "Fruit", len(fruit), &sel, data.ListOptions{}, func(i int) string { return fruit[i] + " row" }, func(i int) {
|
||||
pixel.Text(c, fruit[i], pixel.TextOptions{})
|
||||
})
|
||||
})
|
||||
find(t, tt, "Banana row")
|
||||
// Type-ahead reads key presses, as a keyboard sends them.
|
||||
click(t, tt, "Apple")
|
||||
tt.Key(0, ui.KeyC)
|
||||
tt.Key(0, ui.KeyH)
|
||||
if sel != 2 {
|
||||
t.Fatalf("typing ch chose row %d", sel)
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -23,12 +23,13 @@ type ListResult struct {
|
||||
type listKey struct{}
|
||||
|
||||
// List is a virtual list; ▶ marks the chosen row.
|
||||
func List(c *ui.Context, text string, n int, selected *int, o ListOptions, row func(i int)) ListResult {
|
||||
func List(c *ui.Context, text string, n int, selected *int, o ListOptions, name func(i int) string, row func(i int)) ListResult {
|
||||
k := pixel.K(c)
|
||||
off := o.Disabled || pixel.Current(c).Inert
|
||||
box := ui.Box(c)
|
||||
st := ui.Local(box, listKey{}, func() ui.ListState { return ui.ListState{} })
|
||||
st.Selected = selected
|
||||
// Names read aloud and let typing choose a row.
|
||||
st.Selected, st.Label = selected, name
|
||||
if off {
|
||||
st.Selected = nil
|
||||
}
|
||||
@@ -36,11 +37,11 @@ func List(c *ui.Context, text string, n int, selected *int, o ListOptions, row f
|
||||
box.Children(func() {
|
||||
e = ui.List(c, st, n, pixel.Lazy(c, func(i int) {
|
||||
on := i == *selected
|
||||
// The chosen row is AccentLit under a ▶.
|
||||
// The chosen row is Face: Ink reads on it always.
|
||||
ui.Row(c).FillWidth().Padding(k.D(1), k.D(2), k.D(1), k.D(12)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
if on {
|
||||
g := k.Canvas(p, r)
|
||||
g.Rect(0, 0, g.W, g.H, pixel.AccentLit)
|
||||
g.Rect(0, 0, g.W, g.H, pixel.Face)
|
||||
g.Sprite(3, (g.H-pointer.H)/2, pointer, 0, pixel.Accent, 1)
|
||||
}
|
||||
}).Children(func() { row(i) })
|
||||
|
||||
@@ -30,7 +30,7 @@ func SearchResults(c *ui.Context, label, query string, hits []Hit, selected *int
|
||||
var res ListResult
|
||||
col.Children(func() {
|
||||
pixel.Text(c, fmt.Sprintf(k.Msg("found"), len(hits)), pixel.TextOptions{Slot: pixel.Faint})
|
||||
res = List(c, label, len(hits), selected, ListOptions{Height: o.Height, Disabled: o.Disabled}, func(i int) {
|
||||
res = List(c, label, len(hits), selected, ListOptions{Height: o.Height, Disabled: o.Disabled}, func(i int) string { return hits[i].Title + ", " + hits[i].Text }, func(i int) {
|
||||
ui.Column(c).Children(func() {
|
||||
text.Highlight(c, hits[i].Title, query, text.HighlightOptions{})
|
||||
text.Highlight(c, hits[i].Text, query, text.HighlightOptions{Slot: pixel.Faint})
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ func Transfer(c *ui.Context, text string, left, right *[]string, o TransferOptio
|
||||
// side lists one side's items, its choice kept in range.
|
||||
side := func(name string, items []string, at *int) {
|
||||
*at = max(0, min(*at, len(items)-1))
|
||||
List(c, name, len(items), at, ListOptions{Height: o.Height, Disabled: o.Disabled}, func(i int) {
|
||||
List(c, name, len(items), at, ListOptions{Height: o.Height, Disabled: o.Disabled}, func(i int) string { return items[i] }, func(i int) {
|
||||
pixel.Text(c, items[i], pixel.TextOptions{})
|
||||
}).Element.Width(k.D(100))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user