Elements are now pass-scoped value handles: tests that read bounds after a frame bind a ui.Handle. pixel tells frames apart by the build pass's root, since the Tester clock no longer moves on its own. Fix the regressions the upgrade brought: - Clipboard reads in input handlers go through c.Services(). - MyGo notes an overlay's opener after building it, so AutoFocus inside lost it; pixel.AutoFocus focuses through a Handle, and archtest bans the raw call. Dialogs hand the focus back again. - Elements around a press stay hovered: Tooltip tells a press-given focus by focus arriving under the pointer. - The web host moves the Tester clock with real time, at most 500 ms a call, and gives components the real clock. The gallery's source index also accepts CRLF checkouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package data
|
|
|
|
import (
|
|
"log/slog"
|
|
"slices"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type TransferOptions struct {
|
|
// Height is each list's in dots; zero means 120.
|
|
Height int
|
|
Disabled bool
|
|
}
|
|
|
|
type TransferResult struct {
|
|
Element ui.Element
|
|
Changed bool
|
|
}
|
|
|
|
type transferKey struct{}
|
|
|
|
// Transfer moves chosen items between lists with → ←.
|
|
func Transfer(c *ui.Context, text string, left, right *[]string, o TransferOptions) TransferResult {
|
|
k := pixel.K(c)
|
|
row := ui.Row(c).Gap(k.D(4)).AlignItems(ui.Center).Role(ui.RoleGroup).Label(text)
|
|
sel := ui.Local(row, transferKey{}, func() [2]int { return [2]int{} })
|
|
res := TransferResult{Element: row}
|
|
// 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) string { return items[i] }, func(i int) {
|
|
pixel.Text(c, items[i], pixel.TextOptions{})
|
|
}).Element.Width(k.D(100))
|
|
}
|
|
shift := func(from, to *[]string, at int) {
|
|
if at < 0 || at >= len(*from) {
|
|
return
|
|
}
|
|
*to = append(*to, (*from)[at])
|
|
*from = slices.Delete(*from, at, at+1)
|
|
res.Changed = true
|
|
}
|
|
row.Children(func() {
|
|
side(text+" "+k.Msg("left"), *left, &sel[0])
|
|
ui.Column(c).Gap(k.D(4)).Children(func() {
|
|
if input.IconButton(c, icon.ArrowRight, k.Msg("right"), input.IconButtonOptions{Disabled: o.Disabled || len(*left) == 0}).Clicked {
|
|
shift(left, right, sel[0])
|
|
}
|
|
if input.IconButton(c, icon.ArrowLeft, k.Msg("left"), input.IconButtonOptions{Disabled: o.Disabled || len(*right) == 0}).Clicked {
|
|
shift(right, left, sel[1])
|
|
}
|
|
})
|
|
side(text+" "+k.Msg("right"), *right, &sel[1])
|
|
})
|
|
if res.Changed {
|
|
slog.Debug("8bit: transfer", "label", text, "left", len(*left), "right", len(*right))
|
|
}
|
|
return res
|
|
}
|