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>
101 lines
3.4 KiB
Go
101 lines
3.4 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/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/navigation"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// WizardStep is one page of an OnboardingWizard.
|
|
type WizardStep struct {
|
|
Title, Description string
|
|
Content func()
|
|
// Ready, when set, must return true before Next is allowed.
|
|
Ready func() bool
|
|
}
|
|
|
|
// OnboardingWizardOptions configure an OnboardingWizard.
|
|
type OnboardingWizardOptions struct {
|
|
// NoSkip hides the Skip action.
|
|
NoSkip bool
|
|
}
|
|
|
|
// OnboardingWizardResult reports completion or skipping.
|
|
type OnboardingWizardResult struct {
|
|
Element ui.Element
|
|
finished, skipped bool
|
|
}
|
|
|
|
// Finished reports Finish on the last step.
|
|
func (r OnboardingWizardResult) Finished() bool { return r.finished }
|
|
|
|
// Skipped reports that the user skipped the rest.
|
|
func (r OnboardingWizardResult) Skipped() bool { return r.skipped }
|
|
|
|
// OnboardingWizard provides progress and step navigation.
|
|
func OnboardingWizard(c *ui.Context, step *int, steps []WizardStep, opts OnboardingWizardOptions) OnboardingWizardResult {
|
|
if len(steps) == 0 || *step < 0 || *step >= len(steps) {
|
|
panic(fmt.Sprintf("mujica: OnboardingWizard step %d outside %d steps", *step, len(steps)))
|
|
}
|
|
k := core.Tokens(c)
|
|
d := core.Density(c)
|
|
var r OnboardingWizardResult
|
|
from := *step
|
|
r.Element = ui.Column(c).Gap(d.Unit()*5).Width(520).Padding(d.Unit()*6).Radius(theme.CardRadius).
|
|
Background(k.Surface).Border(theme.BorderWidth, k.Border)
|
|
r.Element.Children(func() {
|
|
head := make([]navigation.Step, len(steps))
|
|
for i, s := range steps {
|
|
if s.Title == "" {
|
|
panic("mujica: WizardStep needs a Title")
|
|
}
|
|
head[i] = navigation.Step{Title: s.Title}
|
|
}
|
|
at := *step
|
|
navigation.Steps(c, &at, head, navigation.StepsOptions{Label: core.Msg(c, "onboarding_wizard.progress")})
|
|
cur := steps[*step]
|
|
ui.Column(c.Key(*step)).Gap(d.Unit() * 3).Children(func() {
|
|
ui.Text(c, fmt.Sprintf(core.Msg(c, "onboarding_wizard.count"), *step+1, len(steps))).TextColor(k.TextMuted).FontSize(core.FontSize(c, theme.CaptionSize))
|
|
ui.Text(c, cur.Title).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H2Size)).FontWeight(600)
|
|
if cur.Description != "" {
|
|
ui.Text(c, cur.Description).TextColor(k.TextMuted)
|
|
}
|
|
if cur.Content != nil {
|
|
cur.Content()
|
|
}
|
|
})
|
|
last := *step == len(steps)-1
|
|
ready := cur.Ready == nil || cur.Ready()
|
|
ui.Row(c).Gap(d.Unit() * 3).AlignItems(ui.Center).Children(func() {
|
|
if !opts.NoSkip && !last && input.Button(c, core.Msg(c, "onboarding_wizard.skip"), input.ButtonOptions{Variant: input.Ghost}).Clicked() {
|
|
r.skipped = true
|
|
}
|
|
ui.Box(c).Grow(1)
|
|
if *step > 0 && input.Button(c, core.Msg(c, "onboarding_wizard.back"), input.ButtonOptions{Variant: input.Secondary}).Clicked() {
|
|
*step--
|
|
}
|
|
next := core.Msg(c, "onboarding_wizard.next")
|
|
if last {
|
|
next = core.Msg(c, "onboarding_wizard.finish")
|
|
}
|
|
if core.AutoFocus(c, input.Button(c, next, input.ButtonOptions{Disabled: !ready})).Clicked() && ready {
|
|
if last {
|
|
r.finished = true
|
|
} else {
|
|
*step++
|
|
}
|
|
}
|
|
})
|
|
})
|
|
if *step != from || r.finished || r.skipped {
|
|
slog.Debug("mujica: onboarding_wizard step", "step", *step, "finished", r.finished, "skipped", r.skipped)
|
|
}
|
|
return r
|
|
}
|