Add code components 366-385; ScrollArea Follow, editor sync

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.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 07:18:30 -04:00
1 parent 0e21870b64
commit 51af14709d
42 files changed
+3415 -37

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
package code
import (
"strings"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// Var is a name, type and value; structs have fields.
type Var struct {
Name, Type, Value string
Fields []Var
}
type VariablesOptions struct {
// Width is in dots; zero means 200.
Width int
Disabled bool
}
type VariablesResult = data.TreeResult
// Variables lists names, types and values; fields open below.
func Variables(c *ui.Context, text string, vars []Var, selected *string, o VariablesOptions) VariablesResult {
return data.Tree(c, text, nodes(vars), selected, data.TreeOptions{Width: pixel.Or("Variables Width", o.Width, 200), Disabled: o.Disabled})
}
// nodes are vars as tree nodes, values colored by kind.
func nodes(vars []Var) []data.TreeNode {
var out []data.TreeNode
for _, v := range vars {
out = append(out, data.TreeNode{Label: v.Name + ": " + v.Type, Value: v.Value, Slot: kind(v), Children: nodes(v.Fields)})
}
return out
}
// kind is a value's slot, read from its type.
func kind(v Var) pixel.Slot {
t := v.Type
switch {
case v.Value == "nil":
return pixel.Faint
case t == "string":
return pixel.Good
case t == "bool":
return pixel.Info
case t == "byte" || t == "rune" || strings.HasPrefix(t, "int") || strings.HasPrefix(t, "uint") || strings.HasPrefix(t, "float") || strings.HasPrefix(t, "complex"):
return pixel.Warn
}
return pixel.Faint
}