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.
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
|
|
)
|
|
|
|
// Hit is one search result.
|
|
type Hit struct {
|
|
Title, Text string
|
|
}
|
|
|
|
type SearchResultsOptions struct {
|
|
// Height is the list's in dots; zero means 120.
|
|
Height int
|
|
Disabled bool
|
|
}
|
|
|
|
type SearchResultsResult = ListResult
|
|
|
|
// SearchResults counts hits and lists them with query matches marked.
|
|
func SearchResults(c *ui.Context, label, query string, hits []Hit, selected *int, o SearchResultsOptions) SearchResultsResult {
|
|
k := pixel.K(c)
|
|
col := ui.Column(c).Gap(k.D(4))
|
|
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) 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})
|
|
})
|
|
})
|
|
})
|
|
if res.Submitted {
|
|
slog.Debug("8bit: search result opened", "label", label, "hit", *selected)
|
|
}
|
|
res.Element = col
|
|
return res
|
|
}
|