Files
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
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>
2026-10-17 01:31:08 -04:00

52 lines
1.4 KiB
Go

package datetime
import (
"log/slog"
"time"
"github.com/egoist/mygo/ui"
)
type DateRangeOptions struct {
Disabled bool
}
type DateRangeResult struct {
Element ui.Element
Changed bool
}
type rangeKey struct{}
// ranging is the keys' day; tail picks the end next.
type ranging struct {
cur time.Time
tail bool
}
// DateRange picks a start, then an end; days between dither.
func DateRange(c *ui.Context, text string, start, end *time.Time, o DateRangeOptions) DateRangeResult {
home := ui.Box(c)
st := ui.Local(home, rangeKey{}, func() ranging { return ranging{cur: *start} })
e, _, picked := month(c, text, &st.cur, o.Disabled, false, func(d time.Time) look {
day := time.Date(d.Year(), d.Month(), d.Day(), 12, 0, 0, 0, time.UTC)
from := time.Date(start.Year(), start.Month(), start.Day(), 12, 0, 0, 0, time.UTC)
to := time.Date(end.Year(), end.Month(), end.Day(), 12, 0, 0, 0, time.UTC)
return look{chosen: sameDay(d, *start) || sameDay(d, *end), between: day.Compare(from) > 0 && day.Before(to)}
})
res := DateRangeResult{Element: e}
if picked {
switch d := st.cur; {
case !st.tail:
*start, *end = onDay(*start, d), onDay(*end, d)
case d.Before(*start):
*start, *end = onDay(*start, d), onDay(*end, *start)
default:
*end = onDay(*end, d)
}
st.tail, res.Changed = !st.tail, true
slog.Debug("8bit: date range", "label", text, "start", start.Format("2006-01-02"), "end", end.Format("2006-01-02"))
}
return res
}