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.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"slices"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type FilterBarOptions struct {
|
|
Disabled bool
|
|
}
|
|
|
|
type FilterBarResult struct {
|
|
Element *ui.Element
|
|
Changed bool
|
|
}
|
|
|
|
// FilterBar toggles filter chips; CLEAR turns them all off.
|
|
func FilterBar(c *ui.Context, text string, labels []string, on []bool, o FilterBarOptions) FilterBarResult {
|
|
k := pixel.K(c)
|
|
if len(on) != len(labels) {
|
|
panic(fmt.Sprintf("data: FilterBar has %d labels, %d flags", len(labels), len(on)))
|
|
}
|
|
row := ui.Row(c).Gap(k.D(4)).AlignItems(ui.Center).Role(ui.RoleGroup).Label(text)
|
|
res := FilterBarResult{Element: row}
|
|
row.Children(func() {
|
|
for i, l := range labels {
|
|
if input.Toggle(c, l, &on[i], input.ToggleOptions{Size: input.Small, Disabled: o.Disabled}).Changed {
|
|
res.Changed = true
|
|
}
|
|
}
|
|
if input.Button(c, k.Msg("clear"), input.ButtonOptions{Size: input.Small, Variant: input.Ghost, Disabled: o.Disabled || !slices.Contains(on, true)}).Clicked {
|
|
clear(on)
|
|
res.Changed = true
|
|
}
|
|
})
|
|
if res.Changed {
|
|
slog.Debug("8bit: filters", "label", text, "on", on)
|
|
}
|
|
return res
|
|
}
|