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>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package code
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type CrashScreenOptions struct {
|
|
// Width is in dots; zero means 260.
|
|
Width int
|
|
Disabled bool
|
|
}
|
|
|
|
type CrashScreenResult struct {
|
|
Element ui.Element
|
|
Continue bool
|
|
}
|
|
|
|
// CrashScreen frames an error and its stack; CONTINUE goes on.
|
|
func CrashScreen(c *ui.Context, err string, stack []string, o CrashScreenOptions) CrashScreenResult {
|
|
k := pixel.K(c)
|
|
if err == "" {
|
|
panic("code: CrashScreen needs an error")
|
|
}
|
|
body, ink, dim := dark(k)
|
|
var res CrashScreenResult
|
|
res.Element = ui.Column(c).Width(k.D(pixel.Or("CrashScreen Width", o.Width, 260))).Padding(k.D(8)).Gap(k.D(4)).
|
|
Role(ui.RoleGroup).Label(k.Msg("game_over")).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Rect(0, 0, g.W, g.H, body)
|
|
// The red frame blinks each second, as the guru's did.
|
|
if g.Step(4)%4 < 2 {
|
|
g.Rect(0, 0, g.W, 3, pixel.Bad)
|
|
g.Rect(0, g.H-3, g.W, 3, pixel.Bad)
|
|
g.Rect(0, 0, 3, g.H, pixel.Bad)
|
|
g.Rect(g.W-3, 0, 3, g.H, pixel.Bad)
|
|
}
|
|
}).Children(func() {
|
|
pixel.Text(c, k.Msg("game_over"), pixel.TextOptions{Slot: pixel.Bad})
|
|
pixel.Text(c, err, pixel.TextOptions{Slot: ink, Wrap: true})
|
|
for _, f := range stack {
|
|
pixel.Text(c, " "+f, pixel.TextOptions{Slot: dim, MaxLines: 1})
|
|
}
|
|
ui.Row(c).Padding(k.D(4), 0, 0, 0).Children(func() {
|
|
res.Continue = input.Button(c, k.Msg("continue"), input.ButtonOptions{Variant: input.Primary, Disabled: o.Disabled}).Clicked
|
|
})
|
|
})
|
|
if res.Continue {
|
|
slog.Debug("8bit: crash screen continue", "error", err)
|
|
}
|
|
return res
|
|
}
|