Add navigation components 131-150; pixel Pad, Finish, Park, Since

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 21:27:09 -04:00
1 parent bd3877e1b1
commit f587d25a5a
63 files changed
+2776 -87

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
package navigation
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
var cross = pixel.MustSprite(`
#...#
.#.#.
..#..
.#.#.
#...#
`)
type DocumentTabsOptions struct {
Disabled bool
}
type DocumentTabsResult struct {
Element *ui.Element
Changed bool
// Closed is the tab × or Delete closed, or -1.
Closed int
}
// DocumentTabs are closable tabs; × or Delete reports Closed.
func DocumentTabs(c *ui.Context, text string, titles []string, selected *int, o DocumentTabsOptions) DocumentTabsResult {
k := pixel.K(c)
res := DocumentTabsResult{Closed: -1}
p := ui.TabsBase(c, selected, len(titles))
p.List.Label(text).Children(func() {
for i, t := range titles {
var x *ui.Element
shell, base, st := pixel.Shell(c, func() *ui.Element {
tab := p.Tab(i).Label(t).Disabled(o.Disabled)
// The × is no Tab stop; Delete closes by keyboard.
tab.Children(func() {
x = ui.Box(c).Absolute().Right(k.D(4)).Top(k.D(6)).Size(k.D(7), k.D(7)).Role(ui.RoleButton).Label(k.Msg("close") + " " + t)
})
return tab
})
if x.Clicked() || base.Shortcut(0, ui.KeyDelete) {
res.Closed = i
}
hot := x.Hovered()
shell.Size(k.D(pixel.Measure(t)+24), k.D(pixel.LineHeight+6)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
folder(g, t, i == *selected, false, st)
ink := pixel.Faint
if hot {
ink = pixel.Bad
}
g.Sprite(g.W-10, 7, cross, 0, ink, 1)
})
}
})
res.Element, res.Changed = p.List, p.List.Changed()
if res.Closed >= 0 {
slog.Debug("8bit: tab closed", "label", text, "tab", titles[res.Closed])
}
return res
}