Files
MujicaUI/account/whats_new_dialog.go
T
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

104 lines
3.1 KiB
Go

package account
import (
"fmt"
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/overlay"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
)
// ChangeKind tags a release note.
type ChangeKind int
const (
ChangeNew ChangeKind = iota
ChangeImproved
ChangeFixed
)
// ReleaseChange is one line of release notes.
type ReleaseChange struct {
Kind ChangeKind
Text string
}
// Release is a version's notes.
type Release struct {
Version, Date string
Changes []ReleaseChange
}
// WhatsNewDialogOptions configure a WhatsNewDialog.
type WhatsNewDialogOptions struct {
// Title replaces the built-in "What's new".
Title string
}
// WhatsNewDialog displays release notes and a persistent hide choice.
func WhatsNewDialog(c *ui.Context, open *bool, hide *bool, releases []Release, opts WhatsNewDialogOptions) core.ChoiceResult {
if len(releases) == 0 {
panic("mujica: WhatsNewDialog needs releases")
}
for _, rel := range releases {
if rel.Version == "" {
panic("mujica: Release needs a Version")
}
for _, change := range rel.Changes {
if change.Kind < ChangeNew || change.Kind > ChangeFixed || change.Text == "" {
panic("mujica: ReleaseChange needs a valid Kind and Text")
}
}
}
if ui.Box(c).IsDisabled() {
*open = false
}
k := core.Tokens(c)
d := core.Density(c)
title := opts.Title
if title == "" {
title = core.Msg(c, "whats_new_dialog.title")
}
var r core.ChoiceResult
was := *open
before := *hide
r.Element = overlay.Dialog(c, open, overlay.DialogOptions{Title: title, Width: 480, Decorated: true, Actions: func() {
input.Checkbox(c, hide, core.Msg(c, "whats_new_dialog.hide"), input.CheckboxOptions{})
ui.Box(c).Grow(1)
if core.AutoFocus(c, input.Button(c, core.Msg(c, "whats_new_dialog.close"), input.ButtonOptions{})).Clicked() {
*open = false
}
}}, func() {
for i, rel := range releases {
if rel.Version == "" {
panic("mujica: Release needs a Version")
}
ui.Column(c.Key(i)).Gap(d.Unit() * 2).Role(ui.RoleGroup).Label(rel.Version).Children(func() {
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.End).Children(func() {
ui.Text(c, rel.Version).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H3Size)).FontWeight(600)
if rel.Date != "" {
ui.Text(c, rel.Date).TextColor(k.TextMuted).FontSize(core.FontSize(c, theme.CaptionSize))
}
})
for _, ch := range rel.Changes {
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.Start).Children(func() {
tone := map[ChangeKind]display.BadgeTone{ChangeNew: display.BadgeAccent, ChangeImproved: display.BadgeInfo, ChangeFixed: display.BadgeSuccess}[ch.Kind]
display.Badge(c, display.BadgeOptions{Text: core.Msg(c, fmt.Sprintf("whats_new_dialog.kind%d", ch.Kind)), Tone: tone}, nil).Shrink(0)
ui.Text(c, ch.Text).Grow(1).MinWidth(0)
})
}
})
}
})
r = core.NewChoiceResult(r.Element, *hide != before)
if was && !*open {
slog.Debug("mujica: whats_new_dialog close", "hide", *hide)
}
return r
}