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

67 lines
1.6 KiB
Go

package datetime
import (
"fmt"
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// AlarmEntry is an alarm: time, days, and if it rings.
type AlarmEntry struct {
Hour, Minute int
// Days ring on, Sunday first.
Days [7]bool
On bool
}
type AlarmOptions struct {
Disabled bool
}
type AlarmResult struct {
Element ui.Element
Changed bool
}
// Alarm lists alarms: time, days and a lever each.
func Alarm(c *ui.Context, text string, alarms []AlarmEntry, o AlarmOptions) AlarmResult {
k := pixel.K(c)
col := ui.Column(c).Gap(k.D(4)).Role(ui.RoleList).Label(text)
res := AlarmResult{Element: col}
names := weekdays(k)
col.Children(func() {
for i := range alarms {
a := &alarms[i]
if a.Hour < 0 || a.Hour > 23 || a.Minute < 0 || a.Minute > 59 {
panic(fmt.Sprintf("datetime: alarm %02d:%02d is no time", a.Hour, a.Minute))
}
at := fmt.Sprintf("%02d:%02d", a.Hour, a.Minute)
ui.Row(c).Gap(k.D(8)).AlignItems(ui.Center).Role(ui.RoleListItem).Label(at).Children(func() {
ink := pixel.Faint
if a.On {
ink = pixel.Ink
}
pixel.Text(c, at, pixel.TextOptions{Slot: ink, Scale: 2})
ui.Row(c).Gap(k.D(3)).Children(func() {
for d, n := range names {
day := pixel.Faint
if a.Days[d] {
day = pixel.Accent
}
pixel.Text(c, n, pixel.TextOptions{Slot: day})
}
})
if input.Switch(c, "", &a.On, input.SwitchOptions{Label: at, Disabled: o.Disabled}).Changed {
res.Changed = true
slog.Debug("8bit: alarm", "label", text, "at", at, "on", a.On)
}
})
}
})
return res
}