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:
42 files changed
+3415
-37
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
)
|
||||
|
||||
type CommandHistoryOptions struct {
|
||||
// Width and Height are dots; zeros mean 200 by 120.
|
||||
Width, Height int
|
||||
Disabled bool
|
||||
}
|
||||
|
||||
type CommandHistoryResult struct {
|
||||
Element *ui.Element
|
||||
// Rerun is Enter or a double click on a command.
|
||||
Changed, Rerun bool
|
||||
}
|
||||
|
||||
// CommandHistory numbers past commands; Enter reruns one.
|
||||
func CommandHistory(c *ui.Context, text string, commands []string, selected *int, o CommandHistoryOptions) CommandHistoryResult {
|
||||
k := pixel.K(c)
|
||||
var r data.ListResult
|
||||
e := ui.Box(c).Width(k.D(pixel.Or("CommandHistory Width", o.Width, 200))).Children(func() {
|
||||
r = data.List(c, text, len(commands), selected, data.ListOptions{Height: o.Height, Disabled: o.Disabled}, func(i int) string { return commands[i] }, func(i int) {
|
||||
ui.Row(c).Gap(k.D(4)).Children(func() {
|
||||
pixel.Text(c, strconv.Itoa(i+1), pixel.TextOptions{Slot: pixel.Faint})
|
||||
pixel.Text(c, commands[i], pixel.TextOptions{MaxLines: 1})
|
||||
})
|
||||
})
|
||||
})
|
||||
if r.Submitted {
|
||||
slog.Debug("8bit: command history rerun", "label", text, "index", *selected)
|
||||
}
|
||||
return CommandHistoryResult{Element: e, Changed: r.Changed, Rerun: r.Submitted}
|
||||
}
|
||||
Reference in new issue
Block a user