Files
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:

- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
  elements expire and Context methods are inert: read IsDisabled into a
  local during the build, keep a ui.Handle for Focus, use c.Services()
  for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
  content builds, so same-frame autofocus lost focus restore on close.
  It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
  c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
  split button tooltip no longer reorders its open menu; disabled
  menubar rows pass presses to the panel; Form defers blur-started
  async checks so the growing message no longer moves Submit away
  from the release; Combobox drops its disabled copy now that MyGo
  blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
  time.Sleep/time.Now and read element state inside the view. The web
  mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.

Snapshot goldens are darwin-only and were not re-verified here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:37:54 -04:00

143 lines
4.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package messaging
import (
"log/slog"
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/datetime"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/internal"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
)
// SnoozePickerOptions configure a SnoozePicker.
type SnoozePickerOptions struct {
// Location is the user's time zone; nil means local.
Location *time.Location
// MorningHour defaults to 9; valid values are 0–23.
MorningHour int
// Now defaults to the frame clock.
Now time.Time
Disabled bool
}
// SnoozeChoice pairs a message key with a reminder time.
type SnoozeChoice struct {
Key string
At time.Time
}
// SnoozeChoices returns localized-day shortcuts using morning hours.
func SnoozeChoices(now time.Time, morning int) []SnoozeChoice {
if morning < 0 || morning > 23 {
panic("mujica: SnoozeChoices morning outside 0..23")
}
day := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
at := func(days int) time.Time {
return time.Date(day.Year(), day.Month(), day.Day()+days, morning, 0, 0, 0, now.Location())
}
var out []SnoozeChoice
if later := now.Add(3 * time.Hour).Truncate(time.Hour); later.Day() == now.Day() {
out = append(out, SnoozeChoice{"snooze_picker.later", later})
}
out = append(out, SnoozeChoice{"snooze_picker.tomorrow", at(1)})
if wd := now.Weekday(); wd != time.Saturday && wd != time.Sunday {
out = append(out, SnoozeChoice{"snooze_picker.weekend", at(int(time.Saturday - wd))})
}
monday := (8 - int(now.Weekday())) % 7
if monday == 0 {
monday = 7
}
return append(out, SnoozeChoice{"snooze_picker.nextWeek", at(monday)})
}
type snoozeState struct {
custom bool
pick time.Time
}
type snoozeKey struct{}
// SnoozePicker offers shortcuts and custom reminder times.
func SnoozePicker(c *ui.Context, until *time.Time, opts SnoozePickerOptions) core.ChoiceResult {
if opts.MorningHour < 0 || opts.MorningHour > 23 {
panic("mujica: SnoozePicker MorningHour outside 0..23")
}
loc := opts.Location
if loc == nil {
loc = time.Local
}
morning := opts.MorningHour
if morning == 0 {
morning = 9
}
k := core.Tokens(c)
d := core.Density(c)
u := d.Unit()
now := opts.Now
if now.IsZero() {
now = c.Now()
}
now = now.In(loc)
old := *until
col := ui.Column(c).Width(300).Padding(u).FocusGroup(ui.Vertical).Role(ui.RoleList).Label(core.Msg(c, "snooze_picker.label")).
Disabled(opts.Disabled)
st := ui.Local(col, snoozeKey{}, func() *snoozeState { return &snoozeState{} })
s := *st
col.Children(func() {
row := func(name, when string, on bool) bool {
b := ui.ButtonBase(c).MinHeight(d.ControlHeight()).Justify(ui.Start).Gap(u*2).Padding(0, u*3).Radius(theme.ControlRadius).
Role(ui.RoleListItem).Label(name + ", " + when).Selected(on).Background(ui.Transparent).Transition(core.ColorFade)
internal.Ring(b, k.Focus, theme.ControlRadius)
switch {
case on:
b.Background(k.Selection).BorderWidth(0, 0, 0, 3).BorderColor(k.AccentText)
case b.Hovered():
b.Background(k.SurfaceHover)
}
b.Children(func() {
ui.Text(c, name).Grow(1).SingleLine()
ui.Text(c, when).FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(k.TextMuted).FontFeatures("tnum").SingleLine()
})
return b.Clicked() && !b.IsDisabled()
}
for _, ch := range SnoozeChoices(now, morning) {
ui.Box(c.Key(ch.Key)).Children(func() {
if row(core.Msg(c, ch.Key), snoozeWhen(c, now, ch.At), until.Equal(ch.At)) {
*until, s.custom = ch.At, false
}
})
}
ui.Box(c).Height(1).Margin(u, 0).Background(k.Border)
if row(core.Msg(c, "snooze_picker.custom"), "", s.custom) {
s.custom = !s.custom
if s.pick.IsZero() {
s.pick = SnoozeChoices(now, morning)[0].At
}
}
if s.custom {
ui.Column(c).Gap(u * 2).Padding(u * 2).Children(func() {
datetime.DateTimePicker(c, &s.pick, datetime.DateTimePickerOptions{Location: loc, Min: now, Label: core.Msg(c, "snooze_picker.custom"), Disabled: opts.Disabled})
if input.Button(c, core.Msg(c, "snooze_picker.set"), input.ButtonOptions{Disabled: !s.pick.After(now)}).Clicked() {
*until = s.pick
}
})
}
})
changed := !until.Equal(old)
if changed {
slog.Debug("mujica: snooze_picker set", "until", *until)
}
return core.NewChoiceResult(col, changed)
}
func snoozeWhen(c *ui.Context, now, t time.Time) string {
if t.Year() == now.Year() && t.YearDay() == now.YearDay() {
return t.Format("15:04")
}
return core.MessagingDate(c, t, "snooze_picker.when")
}