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.
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
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
|
|
}
|