A terminal with history, a Go-colored code block, a log viewer that follows, a hex viewer, a memory map, a JSON tree, a line diff, a GAME OVER crash screen, an FPS meter, profiler bars, breakpoints, variables, command history, a shortcut list, a debug grid, a pixel editor that exports string art, a palette editor, a sprite sheet, a glyph map and a 6502 register view. layout.ScrollArea takes Follow, and ChatLog now uses it. data.TreeNode takes a Value drawn in its Slot. pixel gains Has, and Sprite.Art writes MustSprite art. pixel.Editor takes the caller's value at each input event, so a value changed between frames is never typed onto.
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
|
|
}
|