Add data components 151-175; clear MyGo row highlights
Lists, tables, trees, grids, inventories and records in data/. Outline and GridView build on ui.List: ui.Outline strokes its arrows and ui.GridView spaces and tints items. The pixel theme keeps MyGo's row highlights clear so scrolled rows stay on whole dots; off lists take a veil against the wheel. Adds Canvas.Silhouette, SwitchOptions Label and exports Rarity.Slot.
This commit is contained in:
47 files changed
+3379
-17
No files matched your search
@@ -0,0 +1,45 @@
|
||||
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) {
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user