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>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package datetime
|
||
|
||
import (
|
||
"fmt"
|
||
"log/slog"
|
||
"strconv"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
)
|
||
|
||
type YearPickerOptions struct {
|
||
Disabled bool
|
||
}
|
||
|
||
type YearPickerResult struct {
|
||
Element ui.Element
|
||
Changed bool
|
||
}
|
||
|
||
type yearKey struct{}
|
||
|
||
// YearPicker lays out a decade's years; ◀ ▶ turn decades.
|
||
func YearPicker(c *ui.Context, text string, year *int, o YearPickerOptions) YearPickerResult {
|
||
k := pixel.K(c)
|
||
col := ui.Column(c).Gap(k.D(2))
|
||
st := ui.Local(col, yearKey{}, func() paging { return paging{at: *year - *year%10, cur: *year % 10} })
|
||
res := YearPickerResult{Element: col}
|
||
col.Children(func() {
|
||
pager(c, fmt.Sprintf("%d–%d", st.at, st.at+9), 5*28, o.Disabled, func(d int) {
|
||
st.at += 10 * d
|
||
slog.Debug("8bit: year picker turned", "label", text, "decade", st.at)
|
||
})
|
||
shell, _, ps, picked := pixel.Pad(c, text, 5, 10, 28, cell, &st.cur, o.Disabled)
|
||
if picked >= 0 {
|
||
*year, res.Changed = st.at+picked, true
|
||
}
|
||
at, cur, chosen := st.at, st.cur, *year
|
||
shell.Draw(func(p *ui.Painter, r ui.Rect) {
|
||
g := k.Canvas(p, r)
|
||
for i := range 10 {
|
||
x, y := i%5*28, i/5*cell
|
||
if ps.Focus && i == cur {
|
||
g.Cursor(x, y, 28, cell)
|
||
}
|
||
if at+i == chosen {
|
||
g.Frame(x+1, y, 26, cell, pixel.Sunken, pixel.Well)
|
||
}
|
||
n := strconv.Itoa(at + i)
|
||
g.Text(x+(28-pixel.Measure(n))/2, y, n, pixel.Ink, 1)
|
||
}
|
||
g.Finish(ps)
|
||
})
|
||
})
|
||
if res.Changed {
|
||
slog.Debug("8bit: year picker", "label", text, "year", *year)
|
||
}
|
||
return res
|
||
}
|